First thing I can see is that your xml is invalid, there should be a /
in the last <orderProviderList>. But that's probably not your problem if
it was just a typo in your mail.
Second thing I can see is that you're expecting System.out.println to
print a DOM tree.... I initially tried that and it didn't work either
.Try something like this (taken from the examples on the xml.apache.org
web site or this list or somewhere useful I can't recall...)
//Serialize DOM
OutputFormat format = new OutputFormat( document );
//Writer will be a String
StringWriter stringOut = new StringWriter();
XMLSerializer serial = new XMLSerializer( stringOut, format
);
// As a DOM Serializer
serial.asDOMSerializer();
serial.serialize( document.getDocumentElement() );
//Spit out DOM as a String
System.out.println( "STRXML = " + stringOut.toString() );
System.out.flush();
Cheers,
Andrea
>>> [EMAIL PROTECTED] 05/17/01 10:52AM >>>
Hi everyone
I am new to XML. I am parsing a String into a Document. The string is
parsed into the document and the tags are found but the problem is the
elements are not parsed. If I access the root node by
document.getDocumentElement() it just returns null. But it will still
recognise the root element by the tag name. I am using Xerces version
1.3.1.
Here is my code:
StringReader stringReader = new StringReader(xml);
InputSource inputSource = new InputSource(stringReader);
DOMParser parser = new DOMParser();
try {
parser.parse(inputSource);
} catch (SAXException se) {
System.out.println("Could not load document");
se.printStackTrace();
} catch (IOException ioe) {
System.out.println("Could not load document");
ioe.printStackTrace();
}
Document document = parser.getDocument();
System.out.println(document.getDocumentElement()); //
outputs this -> [orderProviderList: null]
my xml data"
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<orderProviderList><startDate>15-Apr-2001</startDate><endDate>25-Apr-2001</endDate><order><order_no>10002</order_no>
<buyer_name>Heymer</buyer_name><order_date>16/04/2001
08:05</order_date><order_total>R0.00</order_total>
</order><orderProviderList>
Could anyone help me with this
thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]