I want to write a function that parses (theoretically) an unknown XML data structure in an equivalent PHP array.
Here is my XML example:
<?xml version="1.0" encoding="UTF-8"?> <content> <title>Sample Text</title> <introduction> <paragraph>This is some rudimentary text</paragraph> </introduction> <description> <paragraph>Here is some more text</paragraph> <paragraph>Even MORE text</paragraph> <sub_section> <sub_para>This is a smaller, sub paragraph</sub_para> <sub_para>This is another smaller, sub paragraph</sub_para> </sub_section> </description> </content>
I changed this DOM repeat function from devarticals:
$data = 'path/to/xmldoc.xml'; $xmlDoc = new DOMDocument();
Now, due to the way I pass elements to an array, I rewrite any elements that share the node name (since I ideally want to give the keys the same names as their original nodes). My recursion is small ... However, even if I release the brackets, the second level of nodes is still included as values ββin the first level (see text for the description of node).
Anyone have any ideas how I can better build this?
arrays xml loops php parsing
sunwukung
source share