Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing xml with DOM, DOCTYPE gets erased
    text
    copied!<p>how come dom with java erases doctype when editing xml ?</p> <p>got this xml file :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;!DOCTYPE map[ &lt;!ELEMENT map (station*) &gt; &lt;!ATTLIST station id ID #REQUIRED&gt; ]&gt; &lt;favoris&gt; &lt;station id="5"&gt;test1&lt;/station&gt; &lt;station id="6"&gt;test1&lt;/station&gt; &lt;station id="8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre> <p>my function is very basic :</p> <pre><code>public static void EditStationName(int id, InputStream is, String path, String name) throws ParserConfigurationException, SAXException, IOException, TransformerFactoryConfigurationError, TransformerException{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document dom = builder.parse(is); Element e = dom. getElementById(String.valueOf(id)); e.setTextContent(name); // Write the DOM document to the file Transformer xformer = TransformerFactory.newInstance().newTransformer(); FileOutputStream fos = new FileOutputStream(path); Result result = new StreamResult(fos); Source source = new DOMSource(dom); xformer.setOutputProperty( OutputKeys.STANDALONE,"yes" ); xformer.transform(source, result); } </code></pre> <p>it's working but the doctype gets erased ! and I just got the whole document but without the doctype part, which is important for me because it allows me to retrieve by id ! how can we keep the doctype ? why does it erase it? I tried many solution with outputkeys for example or omImpl.createDocumentType but none of these worked...</p> <p>thank you !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload