【问题标题】:RDF+XML response - xml version tag is missingRDF+XML 响应 - 缺少 xml 版本标记
【发布时间】:2013-02-15 10:13:10
【问题描述】:

我有一个 Java sevlet,它创建了一个 RDF/XML-ABBREV 模型。我的问题是响应不包含 xml 版本标记。

目前的回应:

<rdf:RDF
    xmlns:myNS="http://www.sap.de/research/BusinessObjectOntology#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <myNS:Resource rdf:about="http://localhost/myResource">
    ...
  </myNS:Resource>
</rdf:RDF>

但我需要在模型开头使用 &lt;?xml version="1.0"?&gt;。 我是否必须在我的代码中添加一些内容,或者为什么 xml 版本标签不显示?

resp.setCharacterEncoding(CHARSET);
resp.setContentType("application/rdf+xml");
resp.setStatus(HttpStatus.OK_200);
model.write(resp.getWriter(), "RDF/XML-ABBREV");

谢谢

【问题讨论】:

    标签: java xml servlets rdf


    【解决方案1】:

    声明是可选的,但你可以要求它。

    根据the XML writer documentation

    默认行为仅在被要求写入使用 UTF-8 或 UTF-16 以外的其他编码的 OutputStreamWriter 时给出 XML 声明。

    自定义输出尝试:

    ...
    RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
    writer.setProperty("showXmlDeclaration","true");
    writer.write(model, resp.getWriter(), null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多