Conditionally parsing XML attributes with PHP

JohnBrown

New Member
I am really hoping somebody can help me with this.Basically, I am trying to parse certain XML attributes in an XML tree based on other attributes in that branch.As an example of the type of XML I am working with: -\[code\]<root><employees> <team id="1643"> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1364"/> <member id ="153461" jobtype="temporary" division="reception" rollnumber="1326"/> <member id ="153461" jobtype="parttime" division="cleaning" rollnumber="1312"/> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1326"/> </team> <team id="1633"> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1244"/> <member id ="153461" jobtype="temporary" division="reception" rollnumber="1569"/> <member id ="153461" jobtype="parttime" division="cleaning" rollnumber="1472"/> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1112"/> </team> <team id="1674"> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1488"/> <member id ="153461" jobtype="temporary" division="reception" rollnumber="1032"/> <member id ="153461" jobtype="parttime" division="cleaning" rollnumber="1886"/> <member id ="153461" jobtype="permament" division="cleaning" rollnumber="1445"/> </team></employees></root>\[/code\]What I am trying to do is attain the rollnumber for all employees that fill certain categories. So I want to be able to do a that looks like "If jobtype = "permanent" and division = "cleaning" then echo rollnumber".Now, I have tried to parse this with PHP, and basically failed. I failed because I was using syntax such as this: -\[code\]$team->xpath("//member[@jobtype='permament'][@division='cleaning']/@rollnumber")\[/code\]This parses as an array. No problem. I can pull the variables out of the array. No problem.The problem is this...... PHP cannot deal with nested arrays, which this code produces. It holds the initial array in memory and just parses the same variables over and over again. I have tried resetting the array etc at the end of each loop, but that did not work. PHP only seems capable of destroying the array at the end of the foreach sequence.I would really like to know if it is possible to parse this with PHP? Is there a work around for this? Any help/advice would be greaty appreciated.
 
Back
Top