Wie legen schemalocation in ein xml-Dokument per DOM

erstelle ich ein xml-Dokument mit JAXP und Suche einen Weg, um legen Sie die schemalocation.
Im moment ist meine Anwendung erzeugt:

<?xml version="1.0" encoding="UTF-8"?>
<root>
...
</root>

Aber ich brauche:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="namespaceURL" 
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="namespaceURL pathToMySchema.xsd">
...
</root>

Mein code:

StreamResult result = new StreamResult(writer);
Document doc = getDocument();

Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.VERSION, "1.0");
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

DOMSource source = new DOMSource(depl.getAsElement(doc));
trans.transform(source, result);

Vielen Dank für Ihre Zeit,

Kasten

InformationsquelleAutor kasten | 2011-02-02

Schreibe einen Kommentar