如何在XML中使用ESC()字符? [英] How to use ESC () character in XML?
问题描述
我正在尝试:
<root>
text: 
</root>
但解析器说:
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 12;
Character reference "" is an invalid XML character.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
如何使用它?
推荐答案
你不能(在XML 1.0中)。在XML 1.1中,您可以使用稍微更大的字符范围,而字符以不同的方式表示,但即使如此,&#27;
是限制(十六进制是&#x1B ;
),据我所知,这意味着它不是有效的XML,即使XML解析器应该成功处理它。请注意,'null'字符(&#x00;
)从不生效。以下是维基百科文章中关于这些字符的XML
You cannot ( in XML 1.0). In XML 1.1 there is a slightly larger range of characters you can use, and the characters are expressed differently, but even then, 
is 'restricted' (hex it is 
) which, as far as I can tell, means that it is not valid XML, even though XML parsers should process it successfully. Note that the 'null' character (�
) is never valid. Here's a Wiki article on these characters in XML
您可以尝试将XML文档强制为XML 1.1,并查看您的解析器是否会成功处理....将XML的第一行设置为:
You can try forcing the XML document to XML 1.1 and see if your parser will process it successfully.... set the first line of the XML to:
<?xml version="1.1"?>
事实上,我做到了,它的作品:
In fact, I did that, and it works:
<?xml version="1.1"?>
<root></root>
这篇关于如何在XML中使用ESC(&#27;)字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!