Hmm, I'm using Java 1.4.2. When I upgrade the version of xalan to the latest, it starts working. Could it be that namespaces are utterly broken in Java 1.4.2? Looks like it.
Suraj Kumar wrote:
Try invoking : th.startDocument() th.startPrefixMapping(...) ...//Start inserting xml th.endDocument()
----- Original Message ----- From: "Chris B." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, February 01, 2004 8:24 PM
Subject: Help creating XML and namespaces...
xmlns:package="http://preservation.naa.gov.au/package/1.0"></package:packageHi,
I'm converting an application from using JDOM to SAX because I can no longer afford to have the whole XML in memory.
From what I can understand, the best way of generating XML is to use a JAXP Transformer. However when I do this, namespaces don't seem to be generated properly. Also, for no apparent reason, when reading the resulting XML back into JDOM, I get various errors, including "Content is not allowed in prolog" and "Prefix is not bound".
What I would expect in the output is something like....
<?xml version="1.0" encoding="UTF-8"?> <package:package
But what I get is....
<?xml version="1.0" encoding="UTF-8"?> <package:package></package:package>
However, the resulting output and header looks well-formed, and thus the "Content is not allowed in prolog" seems inexplicable.
My code looks something like this... SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); TransformerHandler th = tf.newTransformerHandler(); OutputStream out = new FileOutputStream(file); StreamResult streamResult = new StreamResult(out); th.setResult(streamResult); AttributesImpl att = new AttributesImpl(); th.startElement("http://preservation.naa.gov.au/package/1.0", "package", "package:package", att); th.endElement("http://preservation.naa.gov.au/package/1.0", "package", "package:package");
Is this the correct way to generate XML?
Why aren't namespaces working?
