Problem: A label resolves two times
Stickers for the card bar:
The number of targetPositionX0 and targetPositionY0 in the XML file is exactly the same, but when parsing, Y0 has been parsed two times. followed by the number of characters (not affected).
Online about how to parse XML with sax everywhere, I also mentioned in the previous article, but after today's problem, only know that the previous method is not complete. Below
Let's say the reason why the problem arises.
Sax can parse only about 2k files at a time, so when the contents of the label exceed this size, a second parse is required . reflected in the characters () function to take the label inside
Can not be completed at one time, so the above problems occur. Let's take a look at this diagram.
Explanation: DD is written in the EndElement () function, and we can see that the execution of the two characters executes only after it has been completed.
The correct parsing method:
Private StringBuilder sb = new StringBuilder (); @Override public void characters (char[] ch, int start, int length) throws Saxexception {super. Characters (ch, start, length); Save content to SB sb.append (CH, start, length); } @Override public void Startdocument () throws Saxexception {super.startdocument (); } @Override public void Startelement (string uri, String localname, String qName, Attributes Attributes) throws saxexception {super.startelement (URI, LocalName, qName, attributes); Start a new tab to clear historical data first sb.setlength (0); } @Override public void EndElement (string uri, String localname, String qName) throws Saxexce ption {super.endelement (URI, LocalName, QName); (4) The original value in the characters, is now changed in this value String value = sb.tostring (); Do the appropriate processing} @Override public void EnddocumENT () throws saxexception {super.enddocument (); } }
Android Sax parsing xml two times parsing-------correcting our mistaken perceptions