android - how to parse XML file whith attribute name and catch the value? -



android - how to parse XML file whith attribute name and catch the value? -

am trying parse xml file attribute name.is possible ?

<document type="xxxxx"> <field type="lastname"> <value>abhi</value> </field> <field type="documentnumber"> <value>755327941</value> </field> </document>

i wand parse xml attribute type="lastname" , grab "abhi" in value node.can help me codes because new it. created class can attributes , values.but how can next node , value in it. here code

import java.io.file; import javax.xml.parsers.saxparser; import javax.xml.parsers.saxparserfactory; import org.xml.sax.attributes; import org.xml.sax.saxexception; import org.xml.sax.helpers.defaulthandler; public class parsingxml extends defaulthandler { public static void main(string[] args) throws exception { defaulthandler handler = new parsingxml(); saxparserfactory mill = saxparserfactory.newinstance(); factory.setvalidating(false); saxparser parser = factory.newsaxparser(); parser.parse(new file("result.xml"), handler); } @override public void startelement(string uri, string localname, string qname, attributes attributes) throws saxexception { // number of attributes in list int length = attributes.getlength(); // process each attribute (int i=0; i<length; i++) { // qualified (prefixed) name index string name = attributes.getqname(i); if (name=="type") { string value = attributes.getvalue(i); system.out.println("attribute:" + name); system.out.println("attributevalue:" + value); if(value=="lastname") { //here wand values in value node } } } } }

android

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -