使用SimpleXML和Retrofit无法使用CDATA块解析xml [英] can't parse xml with CDATA block using SimpleXML and Retrofit
本文介绍了使用SimpleXML和Retrofit无法使用CDATA块解析xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法仅从具有 CDATA
块的元素获得价值,仅返回空值,希望你们能为您提供帮助,这是我的xml数据:
i can't seem to get value from only element with CDATA
block, only return empty value, hope you guys can help, this is my xml data:
<response>
<error>
<![CDATA[OK]]>
</error>
<limit>10</limit>
<offset>0</offset>
<number_of_page_results>10</number_of_page_results>
<number_of_total_results>481312</number_of_total_results>
<status_code>1</status_code>
<results>
<issue>
<aliases/>
<api_detail_url>
<![CDATA[http://comicvine.gamespot.com/api/issue/4000-6/]]>
</api_detail_url>
<cover_date>
<![CDATA[1952-10-01]]>
</cover_date>
<date_added>2008-06-06 11:10:16</date_added>
<date_last_updated>2015-07-11 12:08:20</date_last_updated>
<deck/>
<description>
<![CDATA[<p>The horrors of:</p><p>- Lost race!</p><p>- The man germ!</p><p>- Man in the hood!</p><p>- The things!</p><p>-Stories behind the stars, featuring the legendary battle between Hercules, Hydra and Iolaus!</p><p>Plus, two page long prose-stories.</p>]]>
</description>
<has_staff_review></has_staff_review>
<id>6</id>
<image>
<icon_url>
<![CDATA[http://static1.comicvine.com/uploads/square_avatar/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</icon_url>
<medium_url>
<![CDATA[http://static2.comicvine.com/uploads/scale_medium/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</medium_url>
<screen_url>
<![CDATA[http://static3.comicvine.com/uploads/screen_medium/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</screen_url>
<small_url>
<![CDATA[http://static4.comicvine.com/uploads/scale_small/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</small_url>
<super_url>
<![CDATA[http://static5.comicvine.com/uploads/scale_large/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</super_url>
<thumb_url>
<![CDATA[http://static6.comicvine.com/uploads/scale_avatar/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</thumb_url>
<tiny_url>
<![CDATA[http://static7.comicvine.com/uploads/square_mini/5/58993/2645776-chamber_of_chills__13_cgc_8.5.jpg]]>
</tiny_url>
</image>
<issue_number>13</issue_number>
<name>
<![CDATA[The Lost Race]]>
</name>
<site_detail_url>
<![CDATA[http://comicvine.gamespot.com/chamber-of-chills-magazine-13-the-lost-race/4000-6/]]>
</site_detail_url>
<store_date/>
<volume>
<api_detail_url>
<![CDATA[http://comicvine.gamespot.com/api/volume/4050-1487/]]>
</api_detail_url>
<id>1487</id>
<name>
<![CDATA[Chamber of Chills Magazine]]>
</name>
<site_detail_url>
<![CDATA[http://comicvine.gamespot.com/chamber-of-chills-magazine/4050-1487/]]>
</site_detail_url>
</volume>
</issue>
</results>
<version>1.0</version>
</response>
和我的2个模型班:
@Root(name = "response", strict = false)
public class IssueWrapper extends BaseObject {
@ElementList(name = "results")
List<Issue> issues;
public List<Issue> getIssues() {
return issues;
}
}
@Element(name = "issue")
public class Issue extends BaseObject {
@Element(name = "id")
int id;
@Element(name = "date_added")
String dateAdded;
@Element(name = "description", data = true, required = true)
String description;
@Element(name = "issue_number")
int issueNumber;
public String getDateAdded() {
return dateAdded;
}
public int getIssueNumber() {
return issueNumber;
}
}
Logcat输出:
Caused by: org.simpleframework.xml.core.ValueRequiredException: Empty value for @org.simpleframework.xml.Element(data=true, name=description, required=true, type=void) on field 'description' public java.lang.String truongan.android.comicvineapiapp.model.Issue.description in class truongan.android.comicvineapiapp.model.Issue at line 2
推荐答案
使用
@Element(data = true)
对我有用
这篇关于使用SimpleXML和Retrofit无法使用CDATA块解析xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文