[
Lists Home |
Date Index |
Thread Index
]
Hi,
I am a newbie to XML, XML Parsing etc... and am trying to use the DOM
tutorial found at
http://members.fortunecity.com/seagull98/XmlTutorial.html
wich gives a simple example. I am trying to use the attached code to parse
an XML document, construct a DOM tree and traverse the tree and printing the
content. I found the code at the above site. I am also attaching my XML
file.
This is the error I am getting:
The external entity declaration must begin with either "SYSTEM" or "PUBLIC".
[Fatal Error] test.xml:2:21: The external entity declaration must begin with
either "SYSTEM" or "PUBLIC".
Can you help please assist me with this error and provide ideas as to what's
wrong?
Derrick
// This is the part that's meant to do parse the XML file and then acll the walk method below
//get an instance of DomParser
dom.DOMParserWrapper myDOMParser = (dom.DOMParserWrapper) new dom.wrappers.DOMParser();
//Parse the XML File which results in the creation of the Dom tree
Document doc = myDOMParser.parse(traversalNodes.getXMLLocation());
walk(doc);
// The walk method...
//walk the DOM tree and print as u go
private void walk(Node node)
{
int type = node.getNodeType();
switch(type)
{
case Node.DOCUMENT_NODE:
{
System.out.println("<?xml version=\"1.0\" encoding=\""+
"UTF-8" + "\"?>");
break;
}//end of document
case Node.ELEMENT_NODE:
{
System.out.print('<' + node.getNodeName() );
NamedNodeMap nnm = node.getAttributes();
if(nnm != null )
{
int len = nnm.getLength() ;
Attr attr;
for ( int i = 0; i < len; i++ )
{
attr = (Attr)nnm.item(i);
System.out.print(' '
+ attr.getNodeName()
+ "=\""
+ attr.getNodeValue()
+ '"' );
}
}
System.out.print('>');
break;
}//end of element
case Node.ENTITY_REFERENCE_NODE:
{
System.out.print('&' + node.getNodeName() + ';' );
break;
}//end of entity
case Node.CDATA_SECTION_NODE:
{
System.out.print( "<![CDATA["
+ node.getNodeValue()
+ "]]>" );
break;
}
case Node.TEXT_NODE:
{
System.out.print(node.getNodeValue());
break;
}
case Node.PROCESSING_INSTRUCTION_NODE:
{
System.out.print("<?"
+ node.getNodeName() ) ;
String data = node.getNodeValue();
if ( data != null && data.length() > 0 ) {
System.out.print(' ');
System.out.print(data);
}
System.out.println("?>");
break;
}
}//end of switch
//recurse
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
{
walk(child);
}
//without this the ending tags will miss
if ( type == Node.ELEMENT_NODE )
{
System.out.print("</" + node.getNodeName() + ">");
}
}//end of walk
|