parsing - Find node in xml, despite how many nodes deep it might be -


this segment of extremely large xml. i'm super confused how results need it.

<task id="269930118" name="name1" active="0" nexteid="65" tt="cos" ar="0">     <for id="12">         <if id="13">             <when>                 <criteria>                     <comp a="[origname]" test="mask" b="53_inbound_daily_account.txt"/>                 </criteria>                 <updorig action="d" id="45"/>             </when>         </if>     </for>     <if id="37">         <when>             <criteria>                 <comp a="[taskstatus]" test="mask" b="success"/>             </criteria>             <email hostid="282198113" subject="[taskname] [taskstatus]" message="[taskname] [taskstatus]" addressto="email@email.com" usedefretrycount="1" usedefretrytimeoutsecs="1" id="41" type="smtp"/>             <runtask taskid="326261818" wait="0" id="51"/>         </when>     </if>     <if id="39">         <when>             <criteria>                 <comp a="[taskstatus]" test="mask" b="failure"/>             </criteria>             <email hostid="282198113" subject="[taskname] [taskstatus]" message="[taskname] [taskstatus]" addressto="email@email.com" usedefretrycount="1" usedefretrytimeoutsecs="1" id="40" type="smtp"/>         </when>     </if> </task> 

i need add task id arary if following true

comp.a -eq "[taskstatus]" comp.b -eq "failure" email node exists right after comp node. #pseudo code 

so comp , email need within same when node, when node may number of nodes deep xml in given task. i'm super confused how find these. thoughts?

try this:

$ids = @()  $xml = [xml](get-content .\desktop\test.xml)  $xml.task | foreach-object {      if (@($_.selectnodes('./*/when[criteria/comp[@a = "[taskstatus]" , @b = "failure"] , (email)]')).count -gt 0) {         #criterias met. add task id         $ids += $_.id     } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -