Have you tried changing: XMLReader reader = new SAXParser (); reader.parse (uri);
to... SAXParser parser = new SAXParser (); parser.parse (uri); Brion Swanson ------------- Software Engineer West Group Rochester, NY -----Original Message----- From: sateesh [mailto:[EMAIL PROTECTED] Sent: Friday, March 02, 2001 3:29 PM To: '[EMAIL PROTECTED]' Subject: Why the Elements are not parsed??? Hi, I tested the following java program and the xml file i used is HelloWorld.xml which is given at the end and the output I am getting is also given at the end: Please let me know why the startElement and endElement call backs are not getting invoked...Where I went wrong................ import java.io.*; import org.xml.sax.XMLReader; import org.apache.xerces.parsers.*; import org.xml.sax.SAXException; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.ContentHandler; public class SAXParserDemo implements ContentHandler{ private Locator locator; public void setDocumentLocator(Locator locator) { System.out.println("Inside the setDocumentLocator()"); this.locator=locator; } public void startDocument()throws SAXException{ System.out.println("Parisng begins now.................."); } public void endDocument()throws SAXException{ System.out.println("Parisng ended .................."); } public void startElement(String nameSpaceURI,String localName,String rawName,Attributes attr)throws SAXException{ System.out.println("Start Element:"+localName); if(!"".equals(nameSpaceURI)){ System.out.println("In NameSpace "+nameSpaceURI+" ("+rawName+")"); } else{ System.out.println("Has no associated NameSpace"); } } public void endElement(String nameSpaceURI,String localName,String rawName)throws SAXException{ } public void characters(char[] ch,int start,int end)throws SAXException{ } public void ignorableWhitespace(char[] ch,int start,int end)throws SAXException{ } public void skippedEntity(String name)throws SAXException{ } public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) { } public void endPrefixMapping(java.lang.String prefix)throws SAXException{ } public void processingInstruction(java.lang.String target, java.lang.String data) { } public void performDemo(String uri){ System.out.println("Parsing XML File"+uri); try{ System.out.println("Before creating the SAXParser Object"); XMLReader reader=new SAXParser(); reader.parse(uri); System.out.println("After parsing the File"); } catch(IOException ie){ System.out.println("IOException has arised"+ie.getMessage()); } catch(SAXException se){ System.out.println("SAXException has arised"+se.getMessage()); } } public static void main(String args[]){ if(args.length!=1){ System.out.println("Usage: java SAXParserDemo [XML URI]"); System.exit(0); } String uri=args[0]; System.out.println("Before creating the ParseDemo Object"); SAXParserDemo parserDemo=new SAXParserDemo(); System.out.println("After creating the ParseDemo Object"); parserDemo.performDemo(uri); } } THE XML FILE IS GIVEN BELOW.... <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!-- <?xml-stylesheet type="text/xsl" href="foo.xsl"?> --> <foo name="first">Some Sample Text <child>I Am a child1 <d1 name="ram">cell11</d1> <d2>cell12</d2> <d3>cell13</d3> <d4>cell14</d4> </child> <child>I Am a child2 <d1 name="ravi">cell21</d1> <d2>cell22</d2> <d3>cell23</d3> <d4>cell24</d4> </child> </foo> -------------------------- OUTPUT ------------------------ Before creating the ParseDemo Object After creating the ParseDemo Object Parsing XML Filec:\xmlSamples\HelloWorld.xml Before creating the SAXParser Object After parsing the File --------------------------------------------------------------------------- Thanks in advance.............. Regards Sateesh --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
