import org.xml.sax.SAXParseException; import java.io.StringReader; import org.w3c.dom.Document; import oracle.xml.parser.v2.*; public class ParseFromString { public static void main(String[] args) throws Exception { String xmldocString = "<this>"+ " <that/>"+ " <!-- and the other -->"+ "</this>"; // Open a character reader on the string StringReader sr = new StringReader(xmldocString); // Create a new XML Parser DOMParser dp = new DOMParser(); try { // Attempt to parse the reader dp.parse(sr); // Get the parsed document Document xmldoc = dp.getDocument(); // Print the document ((XMLDocument)xmldoc).print(System.out); } catch (SAXParseException spe) { System.out.println(spe.getMessage()); } } } |