| Author |
org.xml.sax.SAXParseException?
|
Tom Barns
Ranch Hand
Joined: Oct 27, 2000
Posts: 138
|
|
Hi all I have the following files and when i compiled them and when i run them i got that exception and i know forsure I'm not either entering the right data at the command line or i have something not right with my xml file.please take a look at them. thanks. //======================== // Copyright 2001 by Jim Weirich (jweirich@one.net). All rights reserved. // Permission is granted for use, modification and distribution as // long as the above copyright notice is included. import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; // =================================================================== // Print the text of all TEXT nodes in the document tree. public class PrintText extends DomDemoFramework { public void traverseTree (Node node) { if (node.getNodeType() == Node.TEXT_NODE) { System.out.println(node.getNodeValue()); } else { NodeList children = node.getChildNodes(); for (int i=0; i<children.getLength(); ++i) { traverseTree (children.item(i)); } } } public void process (Document doc) { traverseTree (doc); } public static void main (String args[]) { PrintText printer = new PrintText(); printer.run(args); } } //======================================================== // Copyright 2001 by Jim Weirich (jweirich@one.net). All rights reserved. // Permission is granted for use, modification and distribution as // long as the above copyright notice is included. import org.w3c.dom.Document; // =================================================================== // Framework for all the DOM Java Demos. All that needs to be done is // to provide an implementation for the `process' method. abstract public class DomDemoFramework { public String program () { return this.getClass().getName(); } public Document getDocument (String uri) throws Exception { org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); parser.parse(uri); return parser.getDocument(); } abstract public void process (Document doc); public void run (String args[]) { run (args, 0); } public void usage () { System.out.println ("Usage: java " + program() + " xmlDocumentUri..."); } public void run (String args[], int start) { System.out.println ("start is "+ start); System.out.println ("run method.............."); System.out.println ("args.length is " + args.length); if (args.length == 0) { System.out.println ("args.length is " + args.length); usage (); System.exit (1); } try { for (int i=start; i<args.length; ++i) { System.out.println ("for loop..........."); System.out.println ("args is ........."+args[i]); Document d = getDocument (args[i]); System.out.println ("Document is "); process (d); } } catch (Exception ex) { System.out.println (ex); } } protected String nodeNames[] = { "<zero node type>", "ELEMENT_NODE", "ATTRIBUTE_NODE", "TEXT_NODE", "CDATA_SECTION_NODE", "ENTITY_REFERENCE_NODE", "ENTITY_NODE", "PROCESSING_INSTRUCTION_NODE", "COMMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_TYPE_NODE", "DOCUMENT_FRAGMENT_NODE", "NOTATION_NODE" }; } //=========================================== <?xml version="1.0"?> <poem xmlns="http://www.megginson.com/ns/exp/poetry"> <title>roses are red </title> <l>roses are red, </l> <l>roses are white </l> <l>roses are blue </l> </poem> //======================================
|
Thanks for your help.
|
 |
 |
|
|
subject: org.xml.sax.SAXParseException?
|
|
|