powershell - Advanced XPath SelectNodes criteria -
i have reached stumbling point in understanding of xpath. can basic selections without trouble, have need select nodes based on not node part of, based on if contain specific node, , keep finding myself going down path of large selection doing loop , if dance whittle down. , somehow think missing nifty trick in xpath in single statement.
so, given xml below, end set of computer nodes, based on particular location id , presence of particular value in set. so, $location = amsterdam & $set = viz should return a-1 computer, $location = amsterdam & $set = arch should return 3 computers in amsterdam.
so, can done purely in xpath statement? , if not, there nifty powershell pipeline trick? or best bet use xpath address location , loop , if strain out sets?
<management> <computers> <location id="amsterdam"> <computer id="a-1"> <conformsets> <set>arch</set> <set>viz</set> </conformsets> </computer> <computer id="a-2"> <conformsets> <set>arch</set> </conformsets> </computer> <computer id="a-3"> <conformsets> <set>arch</set> </conformsets> </computer> </location> <location id="berlin"> <computer id="b-1"> <conformsets> <set>viz</set> </conformsets> </computer> <computer id="b-2"> <conformsets> <set>arch</set> </conformsets> </computer> <computer id="b-3"> <conformsets> <set>arch</set> </conformsets> </computer> </location> </computers> </management>
you can use following xpath form return computer
element based on location
's id
attribute , set
descendant element value :
//location[@id='some_id']/computer[conformsets/set='some_set_value']
Comments
Post a Comment