Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
I am trying to retrieve the xpath of an xml file.
The xml file looks
[syntax="xml"]<CONF_2008 xsi:noNamespaceSchemaLocation="Conference.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OrgLegalName>a</OrgLegalName>
<OrgAcronym>a</OrgAcronym>
....
<HumanResources>
<HRFunction>a</HRFunction>
<HRNberOfStaff>1</HRNberOfStaff>
<HRCost>1</HRCost>
<HRManMonth>1</HRManMonth>
<HRComments>a</HRComments>
</HumanResources>
<E1Staff>1234567891</E1Staff>
<I6OtherCurrentFunding>0</I6OtherCurrentFunding>
</CONF_2008>The result I try to have should be like:
/conf_2008/OrgLegalName
/conf_2008/OrgAcronym
...
/conf_2008/HumanResources
/conf_2008/HumanResources/HRFunction
/conf_2008/HumanResources/HRNberOfStaff
....
/conf_2008/I6OtherCurrentFunding
I am for the moment with something like this:[/syntax]
Code: Select all
<?php
function parseXML($node,$parent)
{
if (!$node->read())
return;
//If this is a text node then test for attributes.
if ($node->nodeType==1)
{
/*print str_pad('',$node->depth,"_",STR_PAD_LEFT).$node->name.'/('.$parent.')<br>';*/
print $parent.'<br>';
$parent .= $node->name.'/';
}
//Call the recursive method again.
parseXML($node,$parent);
}
$reader = new XMLReader();
$reader->open("test_data.xml");
parseXML($reader,"/");
?>Thank you!!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]