开发者

JQuery / XML - problem with & character in XML attribute

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜