简体   繁体   中英

Special characters in XML response received from server

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 replace 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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