How to convert Java String to DOM document Object?
It's a simple thing to do.
Just provide String Object as an InputSource or
InputStream to DocumentBuilder.
Example:
String xmlString;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document =
builder.parse(new InputSource(new StringReader(xmlString)));
This article has moved to my new BLOG.
Labels: Document, DocumentBuilder, DocumentBuilderFactory, W3C, XML
8 Comments:
Hey Shashank,
Great technical stuff, you have put in the Postings..!
Keep doing so...Really Helpful :)
By Vaibhav, at May 16, 2008 10:11 AM
Still helpful a year later. Thanks!
By Chris S, at March 27, 2009 4:12 PM
Well how do u solve it if ur xmlString contains some special characters. The dom building would raise n exception.
By Shobhit, at July 01, 2009 1:37 AM
thanx..
it was really very helpful..
By Anonymous, at April 02, 2010 10:33 AM
Thanks !
By Anonymous, at May 02, 2011 10:08 AM
thanks alot
By Anonymous, at April 21, 2012 12:05 AM
Gracias!
By tec-kids, at July 25, 2013 11:14 AM
I have a error
Caused by: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
By Anonymous, at August 14, 2013 10:25 AM
Post a Comment
<< Home