2016-07-22 8 views
1

유효한 sitemap.xml 파일이 있습니다. 이 파일을 sitemap.xml로 제공하려고하면 문제가 발생합니다. 다음과 같은 오류가 발생합니다 :ASP.NET MVC Sitemap.xml 오류

This page contains the following errors: 

error on line 1 at column 95: Extra content at the end of the document 
Below is a rendering of the page up to the first error. 

브라우저에서 /sitemap.xml을 검사하면 각 요소 태그에서이를 추가합니다. 여기

XmlDocument xml = new XmlDocument(); 
xml.Load(@"C:\sitemap.xml"); 
return Content(xml.DocumentElement.InnerXml, "application/xml"); 

내가 가지고있는 파일의 예입니다 내가 스위칭 시도

<?xml version="1.0" encoding="utf-8"?> 
<urlset 
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> 
    <url> 
    <loc>LINK</loc> 
    </url> 
    THE REST OF URLS 
</urlset> 

반환하려고 : 나는 컨트롤러에서 파일을 반환 방법은 다음과

<url xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
    the rest 
</url> 

입니다 "application/xml"을 "text/xml"로 변경했지만이 문제는 해결되지 않았습니다. XmlDocument를 올바르게 사용하지 않거나 return Content()에서 어떤 일이 발생하는지 완전히 이해하지 못하고 있습니까?

도움을 주시면 감사하겠습니다.

고맙습니다.

답변

1

수정 된 결과는 간단한 수정이었습니다.

XmlDocument xml = new XmlDocument(); 
xml.Load(@"C:\sitemap.xml"); 
return Content(xml.DocumentElement.InnerXml, "application/xml"); 

는이 사람이 나중에 도움이

XmlDocument xml = new XmlDocument(); 
xml.Load(@"C:\sitemap.xml"); 
return Content(xml.DocumentElement.OuterXml, "application/xml"); 

희망으로 변경되었습니다.