james
james

Reputation: 517

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?

Upvotes: 6

Views: 443

Answers (1)

BennyFlint
BennyFlint

Reputation: 610

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.

Upvotes: 3

Related Questions