0

我正在尝试使用 JDOM 解析以下 XML:

<ASX version = "3.0" BANNERBAR="fixed">
<TITLE>HM FM 104.5</TITLE>
<ENTRY>
<TITLE>HM FM 104.5</TITLE>
<BANNER HREF = "http://xxx.xxx.xx.xxx:89/asxbanner.jpg">
<moreinfo href = "http://www.nch.com.au/index.html" />
<abstract>Click here to go to http://www.nch.com.au/index.html</abstract>
</BANNER>
<REF HREF = "http://xxx.xxx.xx.xxx:89/broadwave.mp3?src=1&rate=1&ref=http%3A%2F%2Fxxx.xxx.xx.xxx%3A89%2F" />
</ENTRY>
</ASX>

我的问题是包含“src=1&rate=1&ref=http%3A%2F”的行似乎导致以下异常:

Caused by: org.xml.sax.SAXParseException: The reference to entity "rate" must end with the ';' delimiter.

这是代码:

SAXBuilder builder = new SAXBuilder();
Reader in = new StringReader(xml);
Document doc = null;
Element root = null;
doc = builder.build(in); // this line throws the Exception

看来 JDOM 不喜欢 '&' 或 '=' 字符。如何使用 JDOM 成功解析此 XML?

4

1 回答 1

2

在 XML 字符串中,&字符必须使用&amp;实体。

你的字符串应该是:

"http://xxx.xxx.xx.xxx:89/broadwave.mp3?src=1&amp;rate=1&amp;ref=http%3A%2F%2F111.92.240.134%3A89%2F"
于 2013-05-29T23:53:59.943 回答