简体   繁体   English

转义XML中的特殊字符/符号?

[英]Escape special characters/Symbols in XML?

while creating a XML using a table in my DB , i got many special characters like registered trademark, trademark, degree, different punctuation, etc (these are present in symbol form , hexadecimal, name code , number code )... . 在使用数据库中的表创建XML时,我得到了许多特殊字符,例如注册商标,商标,程度,不同的标点符号等(这些以符号形式,十六进制,名称代码,数字代码显示)...。 some other words like , °, ... 其他一些字词,例如°,...

Also some characters are shown as x99,xEA, etc in my XML. 在我的XML中,某些字符也显示为x99,xEA等。

Is there a library/ API to handle all these while creating XML using JAVA Code. 是否存在使用Java代码创建XML时可以处理所有这些的库/ API。 I am using "UTF-8" character encoding for my XML. 我为XML使用“ UTF-8”字符编码。

Also i cann't clean my DB to have consistent data since it's production data. 另外,由于它是生产数据,因此我无法清理数据库以获取一致的数据。

一种可能的选择是将您的数据包含在CDATA标记中,这会将数据标记为可能包含标记的字符数据,但不应这样处理。

There is a free command line tool for transforming files with special characters in text to valid XML. 有一个免费的命令行工具 ,可将文本中带有特殊字符的文件转换为有效的XML。 It also assures that the file encoding matches what is specified in the declaration. 它还可以确保文件编码与声明中指定的编码匹配。

There is also a Java developer suite that allows you to use the parser to parse such files (called XPL) as an alternative to XML or a pre-process into XML. 还有一个Java开发人员套件,允许您使用解析器来解析此类文件(称为XPL),以替代XML或对XML进行预处理。 It uses a StAX-like process called StAX-PL. 它使用类似于StAX的进程称为StAX-PL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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