我正在尝试使用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&amp; rate = 1&amp; 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不喜欢'&amp;'或'='字符。如何使用JDOM成功解析此XML?
答案 0 :(得分:2)
在XML字符串中,&
字符必须使用&
实体。
你的字符串应该是:
"http://xxx.xxx.xx.xxx:89/broadwave.mp3?src=1&rate=1&ref=http%3A%2F%2F111.92.240.134%3A89%2F"