最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to deal with special characters in URLs inside XML - Stack Overflow

programmeradmin4浏览0评论

I have an XML element that has a url as one of it's children, for example:
;Texas,more+url;data

When parsing this, I'm having two issues:
1.) The (&) symbol breaks the entire parse unless replaced with &amp (which breaks the url)
2.) The ma (,) tries to send my parser on to the next child, resulting in an inplete url.

What can I do to remedy this?
I'm using Javascript and PHP.

I have an XML element that has a url as one of it's children, for example:
http://maps.google./FortWorth&Texas,more+url;data

When parsing this, I'm having two issues:
1.) The (&) symbol breaks the entire parse unless replaced with &amp (which breaks the url)
2.) The ma (,) tries to send my parser on to the next child, resulting in an inplete url.

What can I do to remedy this?
I'm using Javascript and PHP.

Share Improve this question asked Dec 2, 2010 at 23:37 KirtKirt 2,7132 gold badges18 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

Replacing & with & shouldn't break the url. Did you left out the ;?

Better solution is you should wrap that in a CDATA tag:

<![CDATA[ http://maps.google./FortWorth&Texas,more+url;data ]]>

Which tells the XML parser to treat it as text and not parse the &.

There are certain characters which are not valid in XML - you need to "escape" these in the xml document.

These characters and their "escaped" versions are:

>  &gt;
<  &lt;
&  &amp;
'   &apos;
"   &quot;
发布评论

评论列表(0)

  1. 暂无评论