You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ranjith Kodikara <ra...@dmsswt.com> on 2004/10/22 12:44:28 UTC
Problem in DefaultHandler class's startElement() method
Hi,
I am writing a java program to parse an XML file using SAX. In that java class, I am overriding DefaultHandler class's startElement method. This is the code for that method...
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
System.out.print("Start Element: ");
System.out.println(localName);
}
But the output is like this
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Start Element:
Nothing is printed for localName variable.
But when I put qName instead of localName in the System.out.println(qName) it give this result:
Start Element: surveys
Start Element: response
Start Element: question
Start Element: question
Start Element: question
Start Element: question
Start Element: question
Start Element: response
Start Element: question
Start Element: question
Start Element: question
Start Element: question
Start Element: question
Start Element: response
Start Element: question
Start Element: question
Start Element: question
Start Element: question
Start Element: question
It has taken element names for the qName variable.
According to the lesson I am following, this result should come for the localName. But here it takes element names for the qName. Please explain.
The corresponding XML file is given below.
<?xml version="1.0"?>
<surveys>
<response username="bob">
<question subject="appearance">A</question>
<question subject="communication">B</question>
<question subject="ship">A</question>
<question subject="inside">D</question>
<question subject="implant">B</question>
</response>
<response username="sue">
<question subject="appearance">C</question>
<question subject="communication">A</question>
<question subject="ship">A</question>
<question subject="inside">D</question>
<question subject="implant">A</question>
</response>
<response username="carol">
<question subject="appearance">A</question>
<question subject="communication">C</question>
<question subject="ship">A</question>
<question subject="inside">D</question>
<question subject="implant">C</question>
</response>
</surveys>
I will be Grateful for any help.
Best Regards,
Ranjith
Ranjith Kodikara Bsc(Hons), SCJP,SCWCD
Systems Engineer DMS Software Technologies
165, Dharmapala Mawatha,
Colombo 00700
ranjith@dmsswt.com tel:
tel2: +94-11-2673973
+94-11-2696648
Add me to your address book... Want a signature like this?