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
[EMAIL PROTECTED]
tel:
tel2:
+94-11-2673973
+94-11-2696648
Add me to your address book... Want a signature like this?

<<dms.jpg>>

Reply via email to