Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your input XML is not valid. That should be:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;!DOCTYPE favoris [ &lt;!ELEMENT favoris (station)+&gt; &lt;!ELEMENT station (#PCDATA)&gt; &lt;!ATTLIST station id ID #REQUIRED&gt; ]&gt; &lt;favoris&gt; &lt;station id="i5"&gt;test1&lt;/station&gt; &lt;station id="i6"&gt;test1&lt;/station&gt; &lt;station id="i8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre> <p>As @DevNull wrote to be fully valid you can't write <code>&lt;station id="5"&gt;test1&lt;/station&gt;</code> (however for Java it works anyway even with that issue).</p> <hr> <p><code>DOCTYPE</code> is erased in output XML document:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;favoris&gt; &lt;station id="i5"&gt;new value&lt;/station&gt; &lt;station id="i6"&gt;test1&lt;/station&gt; &lt;station id="i8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre> <p>I didn't find solution to missing DTD yet, but as workaround you can set external DTD:</p> <pre><code>xformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "favoris.dtd"); </code></pre> <p>Result (example) document:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;!DOCTYPE favoris SYSTEM "favoris.dtd"&gt; &lt;favoris&gt; &lt;station id="i5"&gt;new value&lt;/station&gt; &lt;station id="i6"&gt;test1&lt;/station&gt; &lt;station id="i8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>I don't think it's possible to save inline DTD using <a href="http://download.oracle.com/javase/6/docs/api/javax/xml/transform/Transformer.html" rel="noreferrer"><code>Transformer</code></a> class (vide <a href="http://www.java.net/external?url=http://markmail.org/message/wj7zz34whcvq3zn7" rel="noreferrer">here</a>). If you can't use external DTD reference, then you can DOM Level 3 <a href="http://download.oracle.com/javase/6/docs/api/org/w3c/dom/ls/LSSerializer.html" rel="noreferrer"><code>LSSerializer</code></a> class instead:</p> <pre><code>DOMImplementationLS domImplementationLS = (DOMImplementationLS) dom.getImplementation().getFeature("LS","3.0"); LSOutput lsOutput = domImplementationLS.createLSOutput(); FileOutputStream outputStream = new FileOutputStream("output.xml"); lsOutput.setByteStream((OutputStream) outputStream); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); lsSerializer.write(dom, lsOutput); outputStream.close(); </code></pre> <p>Output with wanted DTD (I can't see any option to add <code>standalone="yes"</code> using <code>LSSerializer</code>...):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE favoris [&lt;!ELEMENT favoris (station)+&gt; &lt;!ELEMENT station (#PCDATA)&gt; &lt;!ATTLIST station id ID #REQUIRED&gt; ]&gt; &lt;favoris&gt; &lt;station id="i5"&gt;new value&lt;/station&gt; &lt;station id="i6"&gt;test1&lt;/station&gt; &lt;station id="i8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre> <p>Another approach is to use Apache Xerces2-J <code>XMLSerializer</code> class:</p> <pre><code>import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; ... XMLSerializer serializer = new XMLSerializer(); serializer.setOutputCharStream(new java.io.FileWriter("output.xml")); OutputFormat format = new OutputFormat(); format.setStandalone(true); serializer.setOutputFormat(format); serializer.serialize(dom); </code></pre> <p>Result:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;!DOCTYPE favoris [&lt;!ELEMENT favoris (station)+&gt; &lt;!ELEMENT station (#PCDATA)&gt; &lt;!ATTLIST station id ID #REQUIRED&gt; ]&gt; &lt;favoris&gt; &lt;station id="i5"&gt;new value&lt;/station&gt; &lt;station id="i6"&gt;test1&lt;/station&gt; &lt;station id="i8"&gt;test1&lt;/station&gt; &lt;/favoris&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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