Hi guys,
I am trying to parse a simple xml file with SAXParser(jsr 172):
It always throws me SAXParseException every time I want to parse it. But works OK only if I have 1 tag and 1 value in my xml file.Code:<tag1>value1</tag1> <tag2>value2</tag2> <tag3>value3</tag3>
I couldn't find enough good examples or tutorials on how to use it, but here is what I have so far:
Where handler is my extended version of DefaultHandler with following functions:Code:saxFactory = SAXParserFactory.newInstance(); parser = saxFactory.newSAXParser(); handler = new SAXHandler(); parser.parse(is, handler);
When I try to parse the xml file above it prints:Code:// Opening tag public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXParseException { tag = qName; System.out.println(tag); } // Value public void characters(char[] ch, int start, int length) throws SAXParseException { value = new String(ch, start, length); System.out.println(value); } // Closing tag public void endElement(String uri, String localName, String qName, Attributes attrs) throws SAXParseException { hashTable.put(tag, value); }
When I tried to debug it I found out that it never goes to endElement() function, throws exception before it.Code:tag1 value1 org.xml.sax.SAXParseException: at org.xml.sax.helpers.DefaultHandler.fatalError(+1) at com.sun.ukit.jaxp.Parser.panic(+18) at com.sun.ukit.jaxp.Parser.parse(+186) at com.sun.ukit.jaxp.Parser.parse(+47) at com.sun.ukit.jaxp.Parser.parse(+31) ...
Please help,
Thanks.

Reply With Quote


