/* * (C) Copyright IBM Corp. 2004. All rights reserved. * * US Government Users Restricted Rights Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * * The program is provided "as is" without any warranty express or * implied, including the warranty of non-infringement and the implied * warranties of merchantibility and fitness for a particular purpose. * IBM will not be liable for any damages suffered by you as a result * of using the Program. In no event will IBM be liable for any * special, indirect or consequential damages or lost profits even if * IBM has been advised of the possibility of their occurrence. IBM * will not be liable for any third party claims against you. */ import com.ibm.dw.xmlprogjava.DomTreePrinter; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; /** * A sample DOM application. This sample creates a DOM tree from * a String. */ public class ParseString { public void parseAndPrint(InputSource xmlSource) { Document doc = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(xmlSource); if (doc != null) DomTreePrinter.printNode(doc); } catch (Exception e) { System.err.println("Sorry, an error occurred: " + e); } } /** Main program entry point. */ public static void main(String argv[]) { if (argv.length == 1 && argv[0].equals("-help")) { System.out.println("\nUsage: java ParseString"); System.out.println("\nParses an XML document that's " + "contained in a string."); System.exit(1); } ParseString ps = new ParseString(); String markup = new String("