[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problems with using DOM to parse XML


dom.domparserwrapper

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.