我对解析一个 XML 文件感到厌烦。这不是我的,所以我不能编辑它。先看看(我已经剪掉了不必要的部分)
01 <feed>
02 <id>urn:ya.ru:feed/friends/12345678</id>
03 <author>
04 <name>Master</name>
05 <uri>http://test.ya.ru</uri>
06 <y:id>urn:ya.ru:person/12345678</y:id>
07 </author>
08 <title>List of friends posts</title>
09 <updated>2013-08-02T19:14:00Z</updated>
10 <entry>
11 <id>urn:ya.ru:post/110554367/3744</id>
12 <author>
13 <name>MrBigJoker</name>
14 <y:id>urn:ya.ru:person/110554367</y:id>
15 </author>
16 </entry>
17 </feed>
您可以在第 02、06、11 和 14 行看到ID标签。问题是我在第 14 行收到错误“元素ID已被使用”。
我正在使用具有以下三个类的 SimpleXML:
@Root (name = "feed")
public class Feed { // All lines
@Element
private String id;
@Element
private Author_feed author;
@Element
private String title;
@Element
private String updated;
@ElementList(inline = true, type = String.class, entry = "entry")
private List<Entry> entries;
@Root (name = "author")
public class Author_feed { // Lines 03-07
@Element
private String name;
@Element
private String uri;
@Element
@Namespace(prefix = "y")
private String id;
@Root (name = "entry/author")
class Author_entry { // Lines 12-15
@Element
private String name;
@Element
@Path("author")
@Namespace(prefix = "y")
private String id;
@Root (name = "entry")
public class WhatsNewFeed_entry { // Lines 10-16
@Element (name = "id")
private String id_entry;
@Element
private Author_entry author;