Discussion Locked

Problems - String to Document conversion

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

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

CODE :

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;

}

The xml which I am passing is :

Tove
Jani
Reminder
abc

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

Regards,
Suman.

1 reply

by charliespencer

You should post this again but this time use the "Ask a Question" button instead of "Start a Discussion". While some people look at both types of topics, there are quite a few that only look at one or the other. You'll get more technically-oriented readers that way.

This discussion is closed to new replies.