Click to See Complete Forum and Search --> : Problems - Conversion from String XML to Document Object


sumane
04-27-2007, 06:39 AM
Hi,

I am getting some problem while parsing a String XML in to Document object.


public static Document converDocument(String xml)
{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Document document = null;
try {
document = builder.parse(new InputSource(new StringReader(xml)));
System.out.println("Document is after parsing ====>>>"+document);

} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return document;

}


[CODE]

The xml which I am passing is :
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>abc</body>
</note>

[CODE]

It is giving the document as null;
Can anybody please help?

Regards,
Suman.

Stephen Philbin
04-27-2007, 07:21 AM
Which server side language are you using here? I'll move your thread to the relevant forum section so that people that know how to help you with your question will see it.

sumane
04-27-2007, 07:28 AM
I am trying to parse this using Java! Can you please move this thread to related forum and let me know so that I can search for the answer.

Thanks,
Suman.