characters will have many problems. Record them and find them for a long time. It turns out that they are the problem of spaces. Here is the xml file after format and the corresponding print
xml file:
Corresponding log:
Reference: the following excerpt from http://blog.csdn.net/Garmiter/article/details/8016840
XML type 1: no space left
- <?xml version="1.0" encoding="utf-8"?>
- <workers>
- <worker id="1001">
- <name>Garmiter</name>
- <sex>Boy</sex>
- <address>Sichuan Province,Chengdu City</address>
- <money>$2345678</money>
- <status>001</status>
- </worker>
- <worker id="1002">
- <name>Garmiter2</name>
- <sex>Boy2</sex>
- <address>Sichuan Province,Chengdu City</address>
- <money>$23456782</money>
- <status>002</status>
- </worker>
- </workers>
XML type 2: space on the left
- <?xml version="1.0" encoding="utf-8"?>
- <workers>
- <worker id="1001">
- <name>Garmiter</name>
- <sex>Boy</sex>
- <address>Sichuan Province,Chengdu City</address>
- <money>$2345678</money>
- <status>001</status>
- </worker>
- <worker id="1002">
- <name>Garmiter2</name>
- <sex>Boy2</sex>
- <address>Sichuan Province,Chengdu City</address>
- <money>$23456782</money>
- <status>002</status>
- </worker>
- </workers>
android parses XML fragment code - type 1: execute the above XML types only once, execute the above XML types twice and affect the result
- @Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- //System.out.println("-----------tagname="+tagname);
- if(tagname.equals("name")){
- hisname=new String(ch,start,length);
- System.out.println("===="+hisname);
- }else if(tagname.equals("sex")){
- sex=new String(ch,start,length);
- System.out.println("===="+sex);
- }else if(tagname.equals("address")){
- address=new String(ch,start,length);
- System.out.println("===="+address);
- }else if(tagname.equals("money")){
- money=new String(ch,start,length);
- System.out.println("===="+money);
- }else if(tagname.equals("status")){
- status=new String(ch,start,length);
- System.out.println("===="+status);
- }
- }
android parsing XML fragment code - type 2: execute the above XML types only once, and execute the above XML types twice without affecting the result
- @Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- //System.out.println("-----------tagname="+tagname);
- if(tagname.equals("name")){
- hisname=new String(ch,start,length);
- System.out.println("===="+hisname);
- }else if(tagname.equals("sex")){
- sex=new String(ch,start,length);
- System.out.println("===="+sex);
- }else if(tagname.equals("address")){
- address=new String(ch,start,length);
- System.out.println("===="+address);
- }else if(tagname.equals("money")){
- money=new String(ch,start,length);
- System.out.println("===="+money);
- }else if(tagname.equals("status")){
- status=new String(ch,start,length);
- System.out.println("===="+status);
- }
- tagname="";//Give tagname to not meet any of the above conditions, so that no valid steps will be taken for multiple executions
- }