• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

org.xml.sax.SAXParseException?

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
//======================================
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!