问题描述
我有一个 XML 元素,它有一个 url 作为它的子元素之一,例如:
http://maps.google.com/FortWorth&Texas,more+url;data
I have an XML element that has a url as one of it's children, for example:
http://maps.google.com/FortWorth&Texas,more+url;data
在解析这个时,我有两个问题:
1.) (&) 符号会破坏整个解析,除非被替换为 &(会破坏 url)
2.) 逗号 (,) 尝试将我的解析器发送到下一个子节点,从而导致 url 不完整.
When parsing this, I'm having two issues:
1.) The (&) symbol breaks the entire parse unless replaced with & (which breaks the url)
2.) The comma (,) tries to send my parser on to the next child, resulting in an incomplete url.
我该怎么做才能解决这个问题?
我正在使用 Javascript 和 PHP.
What can I do to remedy this?
I'm using Javascript and PHP.
推荐答案
用 &
替换 &
不应该破坏 url.您是否遗漏了 ;?
Replacing &
with &
shouldn't break the url. Did you left out the ;?
更好的解决方案是您应该将其包装在 CDATA 标签中:
Better solution is you should wrap that in a CDATA tag:
<![CDATA[ http://maps.google.com/FortWorth&Texas,more+url;数据 ]]>
<![CDATA[ http://maps.google.com/FortWorth&Texas,more+url;data ]]>
它告诉 XML 解析器将其视为文本而不是解析 &.
Which tells the XML parser to treat it as text and not parse the &.
这篇关于如何处理 XML 中 URL 中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!