Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Xpath syntax for SelectNodes (and/or)

$
0
0

I have the following XML and I am trying to determine the correct XPath syntax to return the count of records where the "Division" node text = "Contracting" and the "Age" node text > 34.

I would like to return the 1 record containing Joe Miller and the following fails with a syntax error (Expected token 'EOF' found 'Name')

MsgBox oXMLPart.SelectNodes("//ns0:Division[text() = 'Contracting'] and //ns0:Age[text() > '34']").Count

Individually,
MsgBox oXMLPart.SelectNodes("//ns0:Division [text() = 'Contracting']").Count
MsgBox oXMLPart.SelectNodes("//ns0:Age[text() >  '34']").Count

Returns 2 and 1 records as expected.

<?xml version="1.0"?><CC_Map_Root xmlns="http://TheAnchorage.com/XMLPart"><Employees xmlns="http://TheAnchorage.com/XMLPart"><EmployeeID>111</EmployeeID><Name>Joe Miller</Name><Age>38</Age><HireDate>2000-09-14</HireDate><Division>Contracting</Division></Employees><Employees xmlns="http://TheAnchorage.com/XMLPart"><EmployeeID>1231</EmployeeID><Name>Tom Smith</Name><Age>33</Age><HireDate>2011-05-09</HireDate><Division>Contracting</Division></Employees><Employees xmlns="http://TheAnchorage.com/XMLPart"><EmployeeID>342</EmployeeID><Name>Tom Armstrong</Name><Age>60</Age><HireDate>1994-05-170</HireDate><Division>Maintenance</Division></Employees></CC_Map_Root>
Can this sort of query be performed?  If so, please assist with the correct syntax.  Thank you.


Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm





Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>