开发者

Special characters in XML response received from server

开发者 https://www.devze.com 2023-03-06 10:39 出处:网络
In my Scala code, I am fetching a response from a server using the getInputStream method of HttpUrlConnection class. The response is XML data. However the data contains HTML entities like & an

In my Scala code, I am fetching a response from a server using the getInputStream method of HttpUrlConnection class. The response is XML data. However the data contains HTML entities like & and '.

Is there a way I can replac开发者_运维知识库e these characters with their text equivalent so that I can parse the XML properly?


It's necessary to encode those entities in xml so they don't interfere with its syntax. The &lt;(<) and &gt; (>) entities make this more obvious. It would be impossible to parse XML whose content was littered with < and > symbols.

Scala's scala.xml package should give you the tools you need to parse your xml. Here's some guidance from the library's author.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号