on advice on here on stackoverflow changed method of parsing saxparser.
thanks different tutorials i'm able work, , have work faster (which important app).
the problem, however, xml file goes deeper tutorial's example xml's i've seen.
this sample of xml file:
<message> <service>servicename</service> <insurances> <breakdowninsurance> <name>insurance name</name> <insurancenr/> <licensenr/> </breakdowninsurance> <cardamageinsurance> <name>insurance name 2</name> <insurancenr></insurancenr> </cardamageinsurance> </insurances> <personal> <name>my name</name> </personal> </message>
i can personal details name, code doesn't seem work insurances. think because it's 1 node more.
this code i'm using in handler class:
@override public void startelement(string namespaceuri, string localname, string qname, attributes atts) throws saxexception { currentelement = true; if (localname.equals("message")) { geg = new gegevensxml(); } } @override public void endelement(string namespaceuri, string localname, string qname) throws saxexception { currentelement = false; /********** autopech **********/ if (localname.equals("name")) { geg.setautopechmaatschappij(currentvalue); } else if (localname.equals("insurancenr")){ geg.setautopechpolis(currentvalue); } else if (localname.equals("licensenr")){ geg.setautopechkenteken(currentvalue); } @override public void characters(char ch[], int start, int length) { if (currentelement) { currentvalue = new string(ch, start, length); currentelement = false; }
so how must adjust it?
@override public void startelement(string namespaceuri, string localname, string qname, attributes atts) throws saxexception { currentelement = true; if (localname.equals("message")) { geg = new gegevensxml(); } if(localname.equals("breakdowninsurance")) { breakdowninsurance = true; } } @override public void endelement(string namespaceuri, string localname, string qname) throws saxexception { currentelement = false; /********** autopech **********/ if (localname.equals("name")) { if(breakdowninsurance) { geg.setbreakdowninsurancename(currentvalue); breakdowninsurance = false; } else { geg.setautopechmaatschappij(currentvalue); } } else if (localname.equals("insurancenr")){ geg.setautopechpolis(currentvalue); } else if (localname.equals("licensenr")){ geg.setautopechkenteken(currentvalue); }
similarly other cases... 'breakdowninsurance' boolean. use flag...
Comments
Post a Comment