我有一个 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>
但我需要<?xml version="1.0"?>
在我的模型的开头。
我是否必须在代码中添加一些内容或者为什么 xml 版本标记不显示?
resp.setCharacterEncoding(CHARSET);
resp.setContentType("application/rdf+xml");
resp.setStatus(HttpStatus.OK_200);
model.write(resp.getWriter(), "RDF/XML-ABBREV");
谢谢
最佳答案
该声明是可选的,但您可以要求它。
根据the XML writer documentation :
The default behaviour only gives an XML Declaration when asked to write to an OutputStreamWriter that uses some encoding other than UTF-8 or UTF-16.
要自定义输出,请尝试:
...
RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
writer.setProperty("showXmlDeclaration","true");
writer.write(model, resp.getWriter(), null);
关于java - RDF+XML 响应 - 缺少 xml 版本标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14892396/