Sometimes unless you know exactly where elements are it can be time consuming to pick each thing up with get_element_by_tagname calls.
I used a quick little function that, given a structure such as:
<customer>
<firstname>Joe</firstname>
<surname>Bloggs</surname>
<age>24</age>
<sex>Male</sex>
...
</customer>
it will return an associative array with the tag names as keys and the content as values. During the load I strip whitespace as well so it isn't confused by \n's creating blank nodes
-- CODE --
$xmldoc = domxml_open_mem($xmlstring,
DOMXML_LOAD_PARSING + //0
DOMXML_LOAD_COMPLETE_ATTRS + //8
DOMXML_LOAD_SUBSTITUTE_ENTITIES + //4
DOMXML_LOAD_DONT_KEEP_BLANKS //16 ));
// get the node root and then the children of it.
$noderoot = $xmldoc->document_element();
$childnodes = $noderoot->child_nodes();
// build the array
foreach ($childnodes as $value) {
echo $value->tagname . " : " . $value->get_content() . "<br>";
$nodeArray[$value->tagname] = $value->get_content();
}
-- END CODE --
You can then return node array or start using it however you like in other functions just like a normal associative array then.
$nodeArray['firstname'] == "Joe"