将 &lt 转换为 <xml文件 [英] convert &lt to < xml document

查看:57
本文介绍了将 &lt 转换为 <xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一个 XML 文件并转换为 NSXMLDocument 对象.但是,由于存在<"在节点的字符串内容中,它已被转换为&lt".因此,当我将其作为 xml 文档写入文件时,其中包含字符&lt".

I have read an XML file and converted into NSXMLDocument object. But, due to the presence of "<" in the string content of a node, it has been converted into "&lt". So, when i write it as xml document to a file, it has the character "&lt" in it.

如何将<"替换为<"的普通 XML 文件写入文件.

How can i write to the file as ordinary XML file in which "&lt" will be replaced by "<".

谢谢和问候,列宁

推荐答案

<字符出现在文本节点时,会被序列化为&lt; 当您将 xml 写入文件时.

When the < character appears in a text node, it will be serialized as &lt; when you write your xml to a file.

当您稍后使用 xml 解析器读取该文件时,文本节点将包含原始 < 字符.

When you later read that file with an xml parser, the text node will contain the original < character.

您还可以选择对文本节点进行 CDATA 编码.在这种情况下,序列化字符是 CDATA 块内的 <.许多 XML API 不会保留 CDATA 和文本节点之间的任何区别.CDATA 应该被视为一种转义机制,使人类作者可以轻松进行编辑.

You also have the option of CDATA encoding the text node. In this case the serialized character is < inside a CDATA block. Many XML APIs will not retain any difference between CDATA and text nodes. CDATA should be thought of as an escaping mechanism to make editing easy for human authors.

这篇关于将 &amp;lt 转换为 &lt;xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆