java - SAX Parser ignoring parent elements? Same named elements grouped as a result -
i'm not if how sax parser supposed work or if missing something.
this sort of xml pulling down server:
<data> <item id="1"> <group> <name>question one</name> <type>true</type> <selection> <name>answer 1</name> </selection> </group> </item> <item id="2"> <group> <name>question two</name> <type>true</type> <selection> <name>answer 2</name> </selection> </group> </item> </data>
as can see, there element called "name" showing twice under different parents, containing different data. trying collect "question one" , "question two" in arraylist have getter , setter of setname getname. title suggest result means answers being collected arraylist type.
is there way pull "name" refers question 1 , question two? here how have in end element:
@override public void endelement(string uri, string localname, string qname) throws saxexception { super.endelement(uri, localname, qname); if (qname.equalsignorecase("name")) { dataitem.setname(currentvalue); }
obviously i'm looking name, when i've tried "group" put second if state inside have not had luck either. it's ignoring parents, group , selection , collecting called name. using localname
not help.
i appreciate help, in advance.
sax pays no attention hierarchy, can compensate in code.
the startelement
, characters
, endelement
methods called appropriately on each start tag, character content , end tag in order appear, want recognize <selection>
tag in startelement
, set flag in handler remember ignore <name>
tags occur until unset flag on hitting </selection>
tag , recognizing in endelement
method.
if post bit more of contenthandler
code, suggest specific changes.
Comments
Post a Comment