Please teach me how to navigate an xml with php.
Have a look at http://laws-lois.justice.gc.ca/eng/XML/C-42.xml.
I made my first attempts to use simplexml_load_file, but what it does is group all the data by tags, which is great at the lower level, but what I need is to preserve some linearity.
In other words, once I get inside , I need to know which Section follows which Heading, etc.
How would I go about that?
<?php
$url="http://laws-lois.justice.gc.ca/eng/XML/C-42.xml";
$xml=simplexml_load_file($url);
echo $xml->Identification->LongTitle;
echo "<br>";
foreach ($xml->Body as $hd) {
// WHAT DO I DO HERE?
}
?>
You can loop over all children of an element in SimpleXML using the
->children()method.foreach ( $simple_xml_doc->children() as $tag ) { ... }will give you a SimpleXML object for each child element, regardless of tag, in the order they appear in the original file.