从控制器操作返回 RDF - ASP.NET MVC
我有一个控制器操作,它将 RDF 文档作为 XML 返回到浏览器。浏览器抱怨文档无法显示:
命名空间前缀不允许以保留字符串“xml”开头。处理资源时出错
我试图使用 MCVContrib 的 XMLResult 对象将文档写入响应流。如何才能让该文档在浏览器中正确显示?我必须写一个普通的字符串吗?
public ActionResult Content(string id, string version, string localization)
{
IDocumentRequest request = new ResourceRequest()
{
Id = id,
Localization = Localization.GetByName(localization),
Version = version
};
XmlDocument doc = _kbModel.GetContent(request);
return new XmlResult(doc);
}
I have a controller action that returns a RDF document as XML to the browser. The browser complains that the document cannot be displayed:
The namespace prefix is not allowed to start with the reserved string "xml". Error processing resource
I was attempting to use MCVContrib's XMLResult object to write the document out to the response stream. How can I have this document displayed correctly to the browser? Do I have to resort to writing a plain string?
public ActionResult Content(string id, string version, string localization)
{
IDocumentRequest request = new ResourceRequest()
{
Id = id,
Localization = Localization.GetByName(localization),
Version = version
};
XmlDocument doc = _kbModel.GetContent(request);
return new XmlResult(doc);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RDF 有一个不同的 MIME 类型,只是 XML。 XMLResult 会将 MIME 类型设置为“application/xml”,而 RDF 需要的是“application/rdf+xml”。您需要设置此手册,或者您可以创建自己的 ActionResult 来设置它。
请参阅:http://www.w3.org/TR/ rdf-syntax-grammar/#section-MIME-Type
RDF has a different MIME type thank just XML. XMLResult will set the MIME type to "application/xml" and what is needed by RDF is "application/rdf+xml". You need to set this manual or you can create your own ActionResult that sets it.
SEE: http://www.w3.org/TR/rdf-syntax-grammar/#section-MIME-Type
您返回的文档的根目录中有一个
xml
命名空间(如 'xmlns:xml="..."')
。或
您使用的是旧版
Microsoft XML (MSXML)
解析器,版本等于Microsoft XML Core Services 4.0
或更低版本。 更新到MSXML 的最新版本< /a>.原因:您在返回的 XML 文档的命名空间前缀(即
xml
)中使用了一个/某些 Microsoft XML (MSXML) 关键字,例如,您有一个类似于 <返回的 xml 文档中的 code>xmlMyProject。请注意,
xml
大小写并不重要,即XMLMyProject
、XmlMyProject
...You have an
xml
namespace (as 'xmlns:xml="..."')
at the root of your returned document.OR
You are using an old
Microsoft XML (MSXML)
parser equal toMicrosoft XML Core Services version 4.0
or lower. Update to the last version of MSXML.Reason: You are using one/some of Microsoft XML (MSXML) keywords in your namespace prefixes in the returned XML document, i.e
xml
,For example you have a namespace like
xmlMyProject
in returned xml document. Note thatxml
capitalization doesn't matter, i.e.XMLMyProject
,XmlMyProject
...