I am trying to write into an XML file using DOMDocument a link that contains the & sign. When I try this, the link becomes & in the xml. So from product=1&qty;=1 becomes product=1&qty;=1.

我正在尝试使用DOMDocument将包含&符号的链接写入一个XML文件。当我尝试此操作时,链接变成&在xml中。由product=1&qty =1变成product=1&qty =1。

Can you please tell me a way to avoid this?

你能告诉我一个避免这种情况的方法吗?

2 个解决方案

#1


4

Ampersands should be encoded like this. Changing it would be wrong.

符号应该像这样编码。改变它将是错误的。

See http://www.w3.org/TR/xml/

参见http://www.w3.org/TR/xml/

The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings &amp; and &lt; respectively.

除作为标记分隔符、注释、处理指令或CDATA部分之外,符号(&)和左角括号(<)不能以它们的文字形式出现。如果在其他地方需要它们,则必须使用数字字符引用或字符串&amp来转义它们。和& lt;分别。

and http://www.w3.org/TR/xhtml1/#C_12

和http://www.w3.org/TR/xhtml1/ C_12

In both SGML and XML, the ampersand character ("&") declares the beginning of an entity reference (e.g., &reg; for the registered trademark symbol "®"). Unfortunately, many HTML user agents have silently ignored incorrect usage of the ampersand character in HTML documents - treating ampersands that do not look like entity references as literal ampersands. XML-based user agents will not tolerate this incorrect usage, and any document that uses an ampersand incorrectly will not be "valid", and consequently will not conform to this specification. In order to ensure that documents are compatible with historical HTML user agents and XML-based user agents, ampersands used in a document that are to be treated as literal characters must be expressed themselves as an entity reference (e.g. "&amp;"). For example, when the href attribute of the a element refers to a CGI script that takes parameters, it must be expressed as http://my.site.dom/cgi-bin/myscript.pl?class=guest&amp;name=user rather than as http://my.site.dom/cgi-bin/myscript.pl?class=guest&name=user

在SGML和XML中,&字符(“&”)都声明实体引用的开头(例如,®注册商标的象征“®”)。不幸的是,许多HTML用户代理都默认忽略了在HTML文档中不正确地使用&和字符——将看起来不像实体引用的&字符视为文字的&字符。基于xml的用户代理不会容忍这种不正确的用法,任何使用&符号不正确的文档都不会是“有效的”,因此不会符合此规范。为了确保文档与历史HTML用户代理和基于xml的用户代理兼容,必须将文档中用作文字字符的&号表示为实体引用(例如)。“,”)。例如,当a元素的href属性引用一个获取参数的CGI脚本时,它必须表示为http://my.site.dom/cgi-bin/myscript.pl?

更多相关文章

  1. 使用PHP捕获正则表达式的字符串的一部分?
  2. php吧字符串直接转换成数组处理
  3. 本机PHP函数将授予我直接访问字符串部分而无需创建临时数组的权
  4. php file_get_content阿拉伯字符
  5. 单引号,双引号,javascript,HTML,转义字符
  6. PHP中出现BOM字符\ufeff,PHP去掉诡异的BOM \ufeff
  7. 从JSON字符串/数组中提取第一个图像
  8. 测试一个字符串是否包含PHP中的单词?
  9. PHP接收到的$_POST数据里的邮箱符号@变成了%40

随机推荐

  1. 2011.07.18(2)——— android Animation的
  2. Android中安装,启动和卸载应用
  3. Android USB debugging 功能失效
  4. Android开发7:单元测试
  5. 仿UC底部菜单栏实例源码
  6. 在Android上创建一个PopupWindow
  7. Android Support Package 支撑包
  8. 在sd卡存储文件
  9. Android(安卓)SB的一面,BUG汇总
  10. Android 解决布局问题