java - SAXParser: handle only specific parent childs -


i have xml structure

<data>    <id>id</id>    <title>datatitle</title>    <entry>       <title>title1</title>    </entry>    <entry>       <title>title2</title>    </entry> </data> 

and want parse , save in list title elements under entry. how can check in endelement title under entry? not have nullpointerexpception because parser tries save title data child.

@override public void startelement(string uri, string localname, string qname, attributes attributes) throws saxexception {     elementon = true;     if ("entry".equals(localname)) {         song = new song();     } }   @override public void endelement(string uri, string localname, string qname) throws saxexception {     elementon = false;      if ("title".equalsignorecase(localname)) {         song.settitle(elementvalue);     } else if ("entry".equalsignorecase(localname)) {         songlist.add(song);     } } 

in case, can use stack push , pop cdata @ startelement , endelement events respectively. put check in endelement event data require stored


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -