문제

maybe a stupid question but I cannot find a way to specify an xml-model tag in my XML output with java DOM. In particular, I'd like that the output XML has the following starting lines:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="URL_TO_MY_RNG_FILE" schematypens="http://relaxng.org/ns/structure/1.0"?>
<root_node>
...
</root_node>

I have also specified the schema in the document factory in this way:

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
Schema schema = schemaFactory.newSchema(new URL("URL_TO_MY_RNG_FILE"));
docFactory.setSchema(schema);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
...

but it seems that it is used only to validate the produced XML and that the XML-Model does not appear in the output XML. Is this the way or I'm just totally wrong? Any suggestion?

Thank you

도움이 되었습니까?

해결책

It might help you to know that the xml-model "tag" is actually a "processing instruction". You'll find methods in the DOM library for creating processing instructions and attaching them to the document node.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top