String to XMLDocument. I have an xml document stored in a String variable. How do I take the String and parse it into an XMLDocument?
Created May 7, 2012
Roseanne Zhang Q. How to parse an XML String?
A: Easy! No matter you using DOM (javax.xml.parsers.DocumentBuilder) or SAX (org.xml.sax.XMLReader), or vendor specific SAXParser/DOMParser, you all can use the same signature method parse(InputSource input) to parse you XML. Now the question becomes how to use String to make an InputSource.
A: Easy! No matter you using DOM (javax.xml.parsers.DocumentBuilder) or SAX (org.xml.sax.XMLReader), or vendor specific SAXParser/DOMParser, you all can use the same signature method parse(InputSource input) to parse you XML. Now the question becomes how to use String to make an InputSource.
- Contruct a StringReader by using your XML String.
- Contruct an InputSource by using your StringReader
- Parse the InputSource by using parse(InputSource input)