开发者

JQuery / XML - problem with & character in XML attribute

开发者 https://www.devze.com 2023-04-08 03:39 出处:网络
I\'m trying to parse an XML document that has an attribute called \"link\" which provides a URL string. The problem is, whenever the URL string includes an & symbol - for example:

I'm trying to parse an XML document that has an attribute called "link" which provides a URL string. The problem is, whenever the URL string includes an & symbol - for example:

http://www.site.com/segment/page.开发者_StackOverflowhtml#/?view=viewName&model=4

The xml parsing breaks and won't parse anything beyond this node. Here's my code:

parseVehicles: function(xmlNode) {  
    $j(xmlNode).children().each(function() {
        console.log(supertree.vehicleCount);
        supertree.vehicleCount++;
    });
},

How do I keep this from breaking?


If your XML looks like this:

<foo link="http://www.site.com/segment/page.html#/?view=viewName&model=4" />

Then that's simply invalid XML. The & should be escaped:

<foo link="http://www.site.com/segment/page.html#/?view=viewName&amp;model=4" />

Fix whatever's creating the invalid XML.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号