从控制器操作返回 RDF - ASP.NET MVC

发布于 2024-10-06 23:22:29 字数 758 浏览 0 评论 0原文

我有一个控制器操作,它将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白云悠悠 2024-10-13 23:22:29

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

离线来电— 2024-10-13 23:22:29

您返回的文档的根目录中有一个 xml 命名空间(如 'xmlns:xml="..."')

您使用的是旧版Microsoft XML (MSXML) 解析器,版本等于Microsoft XML Core Services 4.0 或更低版本。 更新MSXML 的最新版本< /a>.

原因:您在返回的 XML 文档的命名空间前缀(即 xml)中使用了一个/某些 Microsoft XML (MSXML) 关键字,

例如,您有一个类似于 <返回的 xml 文档中的 code>xmlMyProject。请注意,xml 大小写并不重要,即 XMLMyProjectXmlMyProject...

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 to Microsoft 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 that xml capitalization doesn't matter, i.e. XMLMyProject, XmlMyProject...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文