PDA

View Full Version : XPath question


antizip
09-28-2007, 03:33 PM
Howdy all,

In the following XML I'm trying to retrieve /ads/rotator/ad node that doesnt have 'US' in a "restricted" node.

<?xml version="1.0" encoding="utf-8" ?>
<ads>
<rotator appId="IframeRotatingAd">
<ad weight="1" isControl="false" src="">
<text>##AD0##</text>
<restricted />
</ad>
<ad weight="1" isControl="false" src="">
<text>##AD1##</text>
<restricted>US</restricted>
<restricted>MX</restricted>
</ad>
</rotator>
</ads>
I've been trying to use the xpath:
/ads/rotator[@appId='IframeRotatingAd']/ad[restricted!='US']/textBut alas, as you can see here: http://www.xmlme.com/XpathTool.aspx I keep getting it despite my efforts. If i get rid of the

<restricted>MX</restricted>
in the 2nd "ad" node it works, but I need to be able to restrict other countries.

If anyone knows a better way to go about this, please ... let me in on it.

SouthwaterDave
09-29-2007, 09:21 AM
I can see what is wrong with your xpath but I'm not sure I have a simple answer. Your xpath is looking for an ad node with a restricted attribute that is not "US".

You want to find a text node if there is not a restricted node with a text value of "US" immediately under the same ad node. I think you will need some programming rather than just a simple xpath lookup.