久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SimpleXML 很容易解決問題.我做錯了什么?

Very easy to solve issue with SimpleXML. What i#39;m doing wrong?(SimpleXML 很容易解決問題.我做錯了什么?)
本文介紹了SimpleXML 很容易解決問題.我做錯了什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Java 和 SimpleXML

I'm working with Java and SimpleXML

我需要用 SimpleXML 解析這個 XML 文件:

I need to parse this XML file with SimpleXML:

<magazine title="N˙mero 1" id="1">
    <description>yutyutyu</description>
    <miniature>http://web.com/scripts/getImage.php?idMagazine=1&resource=miniature.jpg</miniature>
    <summary>2</summary>
    <pages>
        <page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_001.jpg" id="1" thumbnail="http://web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_001.jpg">
            <areas>
                <area id="1">
                    <top>188</top>
                    <left>204</left>
                    <width>399</width>
                    <height>319</height>
                    <action type="openBrowser">http://www.web.com</action>
                </area>
                <area id="2">
                    <top>188</top>
                    <left>204</left>
                    <width>399</width>
                    <height>319</height>
                    <action type="openBrowser">http://www.web.com</action>
                </area>
            </areas>
        </page>
        <page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_002.jpg" id="2" thumbnail="web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_002.jpg"/>
        <page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_003.jpg" id="3" thumbnail="web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_003.jpg"/>
    </pages>    
</magazine>

我遇到了這個異常:

03-22 16:02:35.072: WARN/System.err(1931): org.simpleframework.xml.core.ValueRequiredException: 無法滿足 @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'areas' public java.util.ArrayList com.Magazine.Page.areas for class com.Magazine.Page 在第 1 行

03-22 16:02:35.072: WARN/System.err(1931): org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'areas' public java.util.ArrayList com.Magazine.Page.areas for class com.Magazine.Page at line 1

雜志有一個頁面數組,每個頁面有一個區域數組,每個區域都有一個動作類,里面有更多的內容.問題肯定出在area數組上,所以在Page類中.

Magazine has an array of pages, and each page has an array of areas, and each area has a action class, which has some more content. The problem must be on areas array, so it is in Page class.

@Root (name="magazine")
public class FullMagazine {
    @Attribute
    String title;
    @Attribute
    String id;
    @Element
    String description;
    @Element
    String miniature;
    @Element
    int summary;
    @ElementList
    public ArrayList<Page> pages;
    
    public String getTitle() {
        return title;
    }
    public String getId() {
        return id;
    }
    public String getDescription() {
        return description;
    }
    public Bitmap getMiniature() {
        return Util.getRemoteBitmap(miniature);
    }   
    
    public static FullMagazine Load(String xml){ 
        Serializer serializer = new Persister();
        try{
            return serializer.read(FullMagazine.class, xml);
        }catch (Exception e) {e.printStackTrace();}
        return null; //si llega aquì es que ha fallado.
    }
}


@Root
public class Page {
    @Attribute
    String src;
    @Attribute
    String id;
    @Attribute
    String thumbnail;
    @ElementList
    public ArrayList<Area> areas;
}


@Root
public class Area {
    @Attribute
    String id;  
    @Element
    int top;
    @Element
    int left;
    @Element
    int width;
    @Element
    int height;
    @Element
    Action action;
}


@Root
public class Action {   
    @Attribute
    String type;    
    
    String action;
}

推薦答案

必須在area的ArrayList上加上required=false,XML的部分Pages沒有Areas

You must put required=false on the ArrayList of areas, some of the Pages of the XML doesn't have Areas

    @Root
public class Page {
    @Attribute
    String src;
    @Attribute
    String id;
    @Attribute
    String thumbnail;
    @ElementList (required=false)
    public ArrayList<Area> areas;
}

這篇關于SimpleXML 很容易解決問題.我做錯了什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 99色视频 | 超碰国产在线 | 日中文字幕在线 | 成人免费黄视频 | 91免费在线视频 | 日韩精品一区二区三区第95 | 一级毛片高清 | 欧美成人精品一区二区男人看 | 黄色片a级 | 一片毛片 | 北条麻妃99精品青青久久主播 | 精品免费国产一区二区三区 | 毛片一区二区三区 | 狠狠婷婷综合久久久久久妖精 | 草草视频在线观看 | 911精品国产 | 亚洲精品久久区二区三区蜜桃臀 | 亚洲在线一区二区 | 国产日韩精品在线 | av色噜噜 | 国产精品视频yy9299一区 | 国产亚洲欧美另类一区二区三区 | 一区精品国产欧美在线 | 国产97在线视频 | av播播 | 女同videos另类 | 欧美群妇大交群中文字幕 | 亚洲国产情侣 | 久久久一区二区三区 | 国产精品一区二区三区四区五区 | 日韩欧美专区 | 亚洲综合一区二区三区 | 涩涩操 | 特黄小视频 | 五月天综合影院 | 国产资源在线视频 | 国产日韩精品在线 | 精品久久av | 国产精品一区二区免费 | 国产成人网| 97国产精品 |