English 中文(简体)
塞内加尔
原标题:SAXParser throws org.apache.harmony.xml.ExpatParser$ParseException

当我试图将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

谁能告诉问题是什么?

问题回答

这个问题已经解决。

我阅读了尿素的xml,并将其写进我的和roid装置的card。 在撰写报告时,我每次用缓冲器读成8个* 1024个。 xml太短了8k,因此,该方案填充了空白的零件。 这造成了问题。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签