Encoding special characters in xml

人盡茶涼 提交于 2019-12-23 02:22:25

问题


How to encode special characters in xml? e.g: i have a special character mu in my xml, transformation will fail due to this character any info would be helpful

Thanks Preetham


回答1:


If you are building up your XML via string concatenation then you need to stop doing that and start using a library (e.g. DOM) in your language to create the XML.

The library will handle encoding correctly.




回答2:


Any valid UTF-8 character should be fine in XML, and any XML processing tool (including XSLT) should handle them also. If the file is valid XML, then it should work. Can you post an example XML file that is giving you trouble?




回答3:


you can encode your xml in utf-8 and use

<node><![CDATA[ odd characters here ]]></node>



回答4:


XML text defaults to the UTF-8 encoding. This supports all characters you care to throw at it. Only by deliberately selecting a non-international encoding would it fail to encode correctly.




回答5:


This is sometimes referred to as "escaping", see here for example.



来源:https://stackoverflow.com/questions/1272136/encoding-special-characters-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!