PHP DOMDocument->包含XML的XML是否包含与号/更少/更大? [英] PHP DOMDocument->loadXML with XML containing ampersand/less/greater?

查看:112
本文介绍了PHP DOMDocument->包含XML的XML是否包含与号/更少/更大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析包含字符&的XML字符串。 <和>在TEXTDATA中。通常,这些字符应该经过html编码,但就我而言,不是,因此我会收到以下消息:

I'm trying to parse an XML string containing characters & < and > in the TEXTDATA. Normally, those characters should be htmlencoded, but in my case they aren't so I get the following messages:

警告:DOMDocument :: loadXML()[function.loadXML ]:实体中的属性名称解析错误...
警告:DOMDocument :: loadXML()[function.loadXML]:找不到开始标记的结尾...

Warning: DOMDocument::loadXML() [function.loadXML]: error parsing attribute name in Entity ... Warning: DOMDocument::loadXML() [function.loadXML]: Couldn't find end of Start Tag ...

我可以使用str_replace对所有&进行编码,但是如果我使用<或>我也为有效的XML标签这样做。

I can use the str_replace to encode all the &, but if I do that with < or > I'm doing it for valid XML tags too.

有人知道这个问题的解决方法吗?

Does anyone know a workaround for this problem??

谢谢!

推荐答案

如果您有< XML内的文字... 这不是有效的XML 。尝试对其进行编码或将其括入<![CDATA [

If you have a < inside text in an XML... it's not a valid XML. Try to encode it or to enclose them into <![CDATA[.

如果不可能(因为您不输出此 XML),我建议尝试使用一些HTML解析库(我没有使用过,但是它们存在),因为它们不如XML严格。

If it's not possible (because you're not outputting this "XML") I'd suggest to try with some Html parsing library (I didn't used them, but they exists) beacuse they're less strict than XML ones.

但是我真的想在尝试任何其他事情之前先获取有效的XML!

But I'd really try to get valid XML before trying any other thing!!

这篇关于PHP DOMDocument-&gt;包含XML的XML是否包含与号/更少/更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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