php parsing complex xml elements into order





I am trying to write a php script which looks at an existing XML log and then print this information to the screen. I been looking at simplexml_load_file() and other methods but I am stuck on one bit. I want to show all information from the elements in order of what they appear in the xml file. I know how to extract values and attributes but what I don't know is how to loop through test and detect and print them in the order as shown below (i.e. 45,46,47,48,49,50. I cannot change the xml structure as it out of my control.


What is the best approach for doing this?


Thanks



<xml>
<test name="test1">
<time date="29/09/2014" />
<message line="45" type="LOG">
<description>Example 1</description>
</message>
<message line="46" type="TEST">
<description>Example 2</description>
</message>
<verification line="47">
<result type="pass" file="abc.py">
<description>button was available</description>
<description type="DETAILED"></description>
</result>
</verification>
<message line="48" type="LOG">
<description>Example 3</description>
</message>
<verification line="49">
<result type="pass" file="abc.py">
<description>button available</description>
<description type="DETAILED"></description>
</result>
</verification>
<message line="50" type="LOG">
<description>Example 4</description>
</message>
</test>
</xml>


Example output:


Test: test1

Date: 29/09/2014

Message - 45 - Log - Description: Example 1

Message - 46 - TEST - Description: Example 2

Verification - 47 - result=pass - button was available - DETAILED - file=abc.py

Message - 48 - Log - Description: Example 3

Verification - 49 - result=pass - button available - DETAILED - file=abc.py

Message - 50 - Log - Description: Example 4


No comments:

Post a Comment