[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
XML strictness
From: |
Robert Schuster |
Subject: |
XML strictness |
Date: |
Tue, 31 May 2005 04:15:16 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.8) Gecko/20050514 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
I got a bug report about our DOM parser which I thought to be valid but
then found something that irritates me.
The following program (probably) demonstrates a problem with Classpath'
DOM parser.
package xmlfilter;
!various imports ommitted!
public class XMLFilter {
public XMLFilter() {
super();
}
public static void main(String[] args) throws Exception {
/*
* parses stdin
*/
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(System.in);
Element newElement = doc.createElement("new");
// The next line makes it unhappy ...
doc.appendChild(newElement);
/*
* serializes xml file to System.out
*/
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer serializer = tfactory.newTransformer();
doc.normalize();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
serializer.transform(new DOMSource(doc),
new StreamResult(System.out));
}
}
When run as 'echo "<a/>" | jamvm -cp . xmlfilter.XMLFilter' you get the
following exception:
gnu.xml.dom.DomDOMException: The node doesn't belong here.
More Information: document element already present:
gnu.xml.dom.DomElement[a]
Node Name: new
at gnu.xml.dom.DomDocument.checkNewChild (DomDocument.java:294)
at gnu.xml.dom.DomDocument.appendChild (DomDocument.java:317)
at xmlfilter.XMLFilter.main (XMLFilter.java:42)
You get the same message with all proprietary JDKs prior to 1.5 . The
latest incarnation however accepts creating the <new> node and generates
the following XML upon calling 'echo "<a/>" |
/opt/sun-jdk-1.5.0/bin/java xmlfilter.XMLFilter':
<?xml version="1.0" encoding="iso-8859-1"?>
<a/>
<new/>
AFAIK there should/must be only one top-level node which is named <xml>.
I am confused ...
Is Sun breaking the rules here?
cu
Robert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFCm8i0G9cfwmwwEtoRAsUyAJ9nU4WtvKJE94oh22WcwWACnjVdqQCcDkNg
SQ3+IUlJgX3N8FLpDSkBeLU=
=XfBm
-----END PGP SIGNATURE-----
- XML strictness,
Robert Schuster <=