如何编码“<"&'>'XML 中的符号 [英] How to encode '<' & '>' Symbols in XML

查看:26
本文介绍了如何编码“<"&'>'XML 中的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 < &> 作为 XML 语法的一部分.如何将这些符号添加为数据的一部分,如

必须有<>符号

我听说有不同类型的数据可以发送 XML,如 CDATA 等,因为字符数据解析每个字符,它不允许这些符号.

我确实知道 &lt;&gt; ,但这没有帮助.

是否有任何数据模式可以发送 XML 以避免任何工具识别符号?

解决方案

在 XML 中有两种表示具有特殊含义的字符的方法(例如 <>) 在 XML 文档中.

  1. CDATA 部分
  2. 作为实体

CDATA 部分只能用在可以有文本节点的地方.

<foo><![CDATA[这里有一些数据,包括<和 >(和&!)]]></foo>

需要注意的是,您不能将序列 ]]> 作为数据包含在 CDATA 部分中.

实体可以在任何地方使用(除了在 CDATA 部分内)并且由 &、一个标识符、; 组成.

<foo>这里有一些数据包括&lt;&gt;(和&amp;!)</foo>

<块引用>

我确实知道 &lt;&gt; ,但这没有帮助.

这就是 XML 的工作原理.这是您仅有的两个选择之一.这应该不是问题(如果是,那么您需要在问题中解释原因).

Since < & > as part of XML syntax. How to add these symbols as part of the data like

<Note>Have to have <> symbols</Note>

I have heard there are different types of data in which XML can be sent like CDATA etc, since character data parses each character it doesn't allow these symbols.

I do know about &lt; and &gt; but that isn't helpful.

Are there are any modes of data in which XML can be sent to avoid any tool recognizing the symbols?

解决方案

There are two ways to represent characters which have special meaning in XML (such as < and >) in an XML document.

  1. CDATA sections
  2. As entities

A CDATA section can only be used in places where you could have a text node.

<foo><![CDATA[Here is some data including < and > (and &!) ]]></foo>

The caveat is that you can't include the sequence ]]> as data in a CDATA section.

Entities can be used everywhere (except inside CDATA sections) and consist of &, then an identifier, then ;.

<foo>Here is some data including &lt; and &gt; (and &amp;!)</foo>

I do know about &lt; and &gt; but that isn't helpful.

It is how XML works. It is one of your only two options. It should not be a problem (if it is, then you need to explain why in your question).

这篇关于如何编码“&lt;"&amp;'&gt;'XML 中的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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