Hi,
I'm trying to implement a simple MVC app, and I want to have the site
map in an XML file.
Anyways, here is the test xml file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<site>
<page id="" name="Home">
</page>
<page id="music" name="Music">
</page>
<page id="pix" name="Pictures">
<page id="news" name="News">
</page>
</page>
</site>
And here is what I get in PHP:
Array ( [tag] => PAGE [type] => complete [level] => 2 [attributes] =>
Array ( [ID] => [NAME] => Home ) [value] => )
Array ( [tag] => SITE [value] => [type] => cdata [level] => 1 )
Array ( [tag] => SITE [value] => [type] => cdata [level] => 1 )
Array ( [tag] => PAGE [type] => complete [level] => 2 [attributes] =>
Array ( [ID] => music [NAME] => Music ) [value] => )
Array ( [tag] => SITE [value] => [type] => cdata [level] => 1 )
Array ( [tag] => SITE [value] => [type] => cdata [level] => 1 )
Array ( [tag] => PAGE [type] => open [level] => 2 [attributes] => Array
( [ID] => pix [NAME] => Pictures ) [value] => )
Array ( [tag] => PAGE [type] => complete [level] => 3 [attributes] =>
Array ( [ID] => news [NAME] => News ) [value] => )
Array ( [tag] => PAGE [value] => [type] => cdata [level] => 2 )
Array ( [tag] => PAGE [type] => close [level] => 2 )
Array ( [tag] => SITE [value] => [type] => cdata [level] => 1 )
Skipping the first and last tag and using the following code:
// convert to php array/parse
$this->siteMap = array();
for ($i=1; $i<count($xmlStruc)-1; $i++) {
$tag = $xmlStruc[$i];
print_r($tag); echo "<p />";
}
What I really want is something like this:
site = array(
"id1" => array("name"=>"namw1","options"=>"",...),
"id2" => array(...),
etc.
);
Perhaps I am not so familiar with how XML is parsed, I get really
frustrated that I'd have to parse all these cdata things and all. Isn't
there a simplier way to create a tree of objects from an XML file? Or do
I really have to take everything into account?
Thanks,
Lüph