当我试图将Xml与SAXParser混入和roid。 last;打赢。 始终存在错误:
org.apache.harmony.xml.ExpatParser$ParseException: At line 15, column 12: not well-formed (invalid token)
这里有我的Xml档案:
<?xml version="1.0" encoding="utf-8"?>
<magazines>
<magazine id="176">
<publising>1</publising>
<price>0</price>
<paid_state>True</paid_state>
<cover_img>http://172.23.5.222/files/images/pub/issue/image-20110517-10bcmaka9bklah8ph57o.jpg</cover_img>
</magazine>
<magazine id="175">
<publising>1</publising>
<price>0</price>
<paid_state>True</paid_state>
<cover_img>http://172.23.5.222/files/images/pub/issue/image-20110517-9jqtrfo5lozztb7m5xlu.jpg</cover_img>
</magazine>
</magazines>
我的手稿
public class BKXMLCoverContentHandler extends DefaultHandler {
private String TAG = "BKXMLCoverContentHandler";
private TreeMap<Integer, Magazine> magazines;
private Magazine magazine;
private String tempString;
private static final String MAGAZINES = "magazines";
private static final String MAGAZINE = "magazine";
private static final String ID = "id";
private static final String PUBLISHING = "publising";
private static final String PRICE = "price";
private static final String PAID_STATE = "paid_state";
private static final String COVER_IMG = "cover_img";
public TreeMap<Integer, Magazine> getMagazines() {
return magazines;
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (magazine != null) {
String valueString = new String(ch, start, length);
if (PUBLISHING.equals(tempString)) {
Log.d(TAG, valueString);
magazine.setPublishingStatus(valueString);
} else if (PRICE.equals(tempString)) {
Log.d(TAG, valueString);
magazine.setPrice(valueString);
} else if (PAID_STATE.equals(tempString)){
Log.d(TAG, valueString);
magazine.setPaidStatus(tempString);
} else if (COVER_IMG.equals(tempString)){
Log.d(TAG, valueString);
magazine.setCoverUrl(valueString);
}
}
}
@Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
if (MAGAZINES.equals(localName)){
Log.d(TAG, localName);
magazines = new TreeMap<Integer, Magazine>();
}
if (MAGAZINE.equals(localName)) {
magazine = new Magazine();
Log.d(TAG, localName);
magazine.setId(new Integer(attributes.getValue(ID)));
}
tempString = localName;
}
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
if(MAGAZINE.equals(localName) && magazine != null){
Log.d(TAG, localName);
magazines.put(magazine.getId(), magazine);
magazine = null;
} else if(MAGAZINES.equals(localName)){
Log.d(TAG, localName);
}
tempString = null;
}
}
从法典上看,你可以看到我有条不紊地生产所有线。 因此,我得出一个记录产出:
D/BKXMLCoverContentHandler( 980): magazines
D/BKXMLCoverContentHandler( 980): magazine
D/BKXMLCoverContentHandler( 980): 1
D/BKXMLCoverContentHandler( 980): 0
D/BKXMLCoverContentHandler( 980): True
D/BKXMLCoverContentHandler( 980): http://172.23.5.222/files/images/pub/issue/image-20110517-10bcmaka9bklah8ph57o.jpg
D/BKXMLCoverContentHandler( 980): magazine
D/BKXMLCoverContentHandler( 980): magazine
D/BKXMLCoverContentHandler( 980): 1
D/BKXMLCoverContentHandler( 980): 0
D/BKXMLCoverContentHandler( 980): True
D/BKXMLCoverContentHandler( 980): http://172.23.5.222/files/images/pub/issue/image-20110517-9jqtrfo5lozztb7m5xlu.jpg
D/BKXMLCoverContentHandler( 980): magazine
D/BKXMLCoverContentHandler( 980): magazines
谁能告诉问题是什么?