I tried to update from JDOM 1.0 to JDOM2. In JDOM 1.0 this code:
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
org.w3c.dom.Document doc = dbFactory.newDocumentBuilder().newDocument();
doc.setXmlVersion("1.0");
Element root = doc.createElement("Document");
root.setAttribute("xmlns", "urn:iso:foo");
root.setAttribute("xsi:schemaLocation", "urn:iso:foo bar.xsd");
root.setAttribute("xmlns:xsi", "http://ift.tt/ra1lAU");
doc.appendChild(root);
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("testxml.xml"), "UTF8"));
DOMBuilder builder = new DOMBuilder();
Document jdoc = builder.build(doc);
XMLOutputter fmt = new XMLOutputter();
fmt.setFormat(Format.getPrettyFormat());
fmt.output(jdoc, out);
produces this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:foo" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="urn:iso:foo bar.xsd" />
When I use JDOM2, the attribute xsi:schemaLocation is changed to schemaLocation (and the XML looks like that):
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:foo" xmlns:xsi="http://ift.tt/ra1lAU" schemaLocation="urn:iso:foo bar.xsd" />
Is there a way to keep the xsi: part in JDOM2? Without it, the system which processes the generated XML cannot read it (not under my control). Not sure whether this is the same question.
No comments:
Post a Comment