XPath: Select multiple child nodes - TechRepublic
Question
November 16, 2010 at 12:43 PM

XPath: Select multiple child nodes

by . Updated 15 years, 7 months ago

Given the following sample “xml” file (tags won’t display correctly, so I used spaces instead of angle brackets. All nodes are elements, no attributes)…

USGovernment
–President
—-Order 1 /Order
—-FirstName George /FirstName
—-LastName Washington /LastName
–/President
–… and so on
/USGovernment

I can easily select the President nodes of George and Honest Abe.

//President[Order=’1′ or Order=’16’]

But how would I return their names without repeating the query string above?

//President[Order=’1′ or Order=’16’]/FirstName | //President[Order=’1′ or Order=’16’]/LastName

works, but is there a shorthand way of writing this? In my real data that repeated portion of the query is much longer.

Thanks,

This discussion is locked

All Comments