[英]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. 在我的Scala代码中,我使用HttpUrlConnection
类的getInputStream
方法从服务器获取响应。 The response is XML data. 响应是XML数据。 However the data contains HTML entities like &
但是,数据包含HTML实体,如&
and '
和'
. 。
Is there a way I can replace these characters with their text equivalent so that I can parse the XML properly? 有没有办法可以用等效的文本替换这些字符,以便我能正确解析XML?
It's necessary to encode those entities in xml so they don't interfere with its syntax. 有必要在xml中对这些实体进行编码,这样它们就不会干扰它的语法。 The <
<
(<) and >
(<)和>
(>) entities make this more obvious. (>)实体使这更加明显。 It would be impossible to parse XML whose content was littered with < and > symbols. 解析其内容充满<和>符号的XML是不可能的。
Scala's scala.xml package should give you the tools you need to parse your xml. Scala的scala.xml包应该为您提供解析xml所需的工具。 Here's some guidance from the library's author. 以下是图书馆作者的一些指导 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.