简体   繁体   English

使用特殊字符解析XML时出现JDOM SAXParseException

[英]JDOM SAXParseException when parsing XML with special characters

I'm trying to parse the following XML using JDOM: 我正在尝试使用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>

My issue is the line containing "src=1&rate=1&ref=http%3A%2F" appears to cause the following exception: 我的问题是包含“src = 1&rate = 1&ref = http%3A%2F”的行似乎导致以下异常:

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

Here is the code: 这是代码:

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

It appears JDOM doesn't like the '&' or '=' character. 似乎JDOM不喜欢'&'或'='字符。 How can I use JDOM to successfully parse this XML? 如何使用JDOM成功解析此XML?

In XML strings, the & character must use the &amp; 在XML字符串中, &字符必须使用&amp; entity. 实体。

Your string should be: 你的字符串应该是:

"http://xxx.xxx.xx.xxx:89/broadwave.mp3?src=1&amp;rate=1&amp;ref=http%3A%2F%2F111.92.240.134%3A89%2F"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM