Can someone please help me work out how to output the below XML file in PHP
XML:
<student>
<name>studentname</name>
<map>
<competency>
<level>5</level>
<skill name="Maths">
<skillinfo> "some value" </skillinfo>
</skill>
<competency>
<competency>
<level>4</level>
<skill name="Science">
<skillinfo> "some value" </skillinfo>
</skill>
<competency>
<competency>
<level>5</level>
<skill name="Technology">
<skillinfo> "some value" </skillinfo>
</skill>
<competency>
</map>
</student>
Code I've so far:
$dom = new DOMDocument;
$dom->loadXML($data);
$xpath = new DomXpath($dom);
$x = $dom->documentElement;
echo "<table class='blueTable' >
<thead>
<tr>
<th>Student Name</th>
<th>Skill</th>
<th>Level</th>
</tr>
</thead>
<tbody>
<tr> ";
foreach ($xpath->query('//skill') as $item) {
foreach($item->parentNode->childNodes as $node)
if ($node->tagName == 'level')
echo "<td>" . $node->nodeValue . "</td>";
}
The above code outputs all the levels found in the XML file for that student. Each student has their own XML file, but you don't need to worry about that complexity. Lets work out how to output just one student, their skill and level first.
I'm using XDOM and what I'd like to do is:
In a table I'd like list first the student name, skill name (maths), and the level information. This needs to be iterated as there are multiple skills and levels within each skill for each student.
I can work out how to find something via XPATH and then locate its parent but can't seem to figure out how to loop this properly. Please help :)
Thank you