java - SAX parser get attribute from endelement -


I use the X XML parser and when I use it:

  Public zero start element (string yuri), string local name, string qName, attribute features) throws SAXException   

I can get properties but I public zero end element

  & lt; Item name = "test" value = Somedata "/> Code:  

Public class SAXXMLHandler extends the default handler { Private Arrestist & lt; itemsList & gt; Item; Private String Tempel; Private Item List tempEmp; Private Package Manager Manager; Personal String Packname; Public SAXXMLHandler (Package Manager Manager, String Packname) {items = New Arrestist & Lt; itemlist & gt; (); it; manager = manager; this.packName = packName;} public Nero character (four [] f, integer start, integer length) throws SAXException {tempVal = new string (ch, start, length);} // event handlers public zero start element (string yuri, string locallime, string qName, attribute characteristics If the (qName.equalsIgnoreCase ("item")) {log in ("INFO", "startElement" + local name + "," + qName + "," + attributes "); // {Reset tempVal =" " // Employee create a new instance of tempEmp = new item list (); tempEmp.setName (attributes.getValue ("name"));}} public Zero end element (string yuri, string local name, string qName) SAXException {throws log ("INFO", "EndAlment" + local name + "," + qName); }

and do not logcat from startlelele

UPDATE

I use in slice:

  SAXXMLHandler handler = New SAXXMLHandler (); SAXParserFactory factory = SAXParserFactory.newInstance (); SAXParser saxParser = factory.newSAXParser (); SaxParser.parse (property, handler); Item = SAXXMLHandler.icons; Util.l (String.valueOf (SAXXMLHandler.icons.size ())); // log (item list item: SAXXMLHandler.icons) {Util.l (item.getComponent () + "\ t \ t" + item.getComponent ()); // log}   

See SAXXMLHandler:

  public square SAXXMLHandler default handler {public static ArrayList & lt; ItemsList & gt; item; Private item list item; Public SAXXMLHandler () {items = new ArrayList & lt; Item list & gt; (); } Public Zero Character (four [] ch, int start, int length] SAXException {} Public Zero Start Element throws (string uri, string local name, string qName, attribute characteristics) SAXException {item = new itemsList (); Log D. ("INFO", "Start Element" + Local Name + "," + qName); If (qName.equalsIgnoreCase ("item")) {item.setComponent (attributes.getValue ("component")); Items.add (item); }} Public Zero End Element throws SAXException {}}   

and still nothing: /

XML file I

In the given XML line.

  & lt; Item name = "test" value = "somedata" />   

names and values ​​ are attributes that can only be retrieved in the startElement () method . Because, property attributes parameter is passed only in startElement (string yuri, string localname, string qName, attribute attributes) method. If you see the endElement (string yurry, string locallime, string qName) method, then attribute attributes is not the reason that you endElement () can not retrieve any attribute in the method. Therefore, if you want to retrieve the attributes from XML , then you should call them startElement (string Yury , String location name, string, qName, attributes, attributes) method

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -