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.
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.