Bleh... I know we've got some PHP monkeys in here, throw me a bone...
I'm trying to parse an XML document (with no attributes - just plain tagnames and cdata) into a nested array, so I can preserve the data structure, so the result would be something like...
That sort of thing. A quick start seemed to be to use xml_parse_into_struct(), then I figured I'd loop through that array and build my hierarchy, but I'm having an issue trying to record my current position in the array I'm building, or - more correctly - referencing that position successfully to do the assignment when I come across a cdata value that I want to store.
I'm using a stack, $pos, and each time I come across an open tag I push the tagname onto that stack, and each time I find a closing tag I pop it off. So at any given time I've got a stack something like:
And I want to concatenate those elements into a usable array reference, $arr[tagname][0][var], to do the assignment.
I've tried concatting the lot into a string and using that string as a variable variable, but that doesn't work. It's 2am and my mind is blank - any suggestions?
I'm trying to parse an XML document (with no attributes - just plain tagnames and cdata) into a nested array, so I can preserve the data structure, so the result would be something like...
$arr
[tagname]
[0]
[tagname]
[var]=<val>
[1]
[tagname]
[var]=<val>
etc.
That sort of thing. A quick start seemed to be to use xml_parse_into_struct(), then I figured I'd loop through that array and build my hierarchy, but I'm having an issue trying to record my current position in the array I'm building, or - more correctly - referencing that position successfully to do the assignment when I come across a cdata value that I want to store.
I'm using a stack, $pos, and each time I come across an open tag I push the tagname onto that stack, and each time I find a closing tag I pop it off. So at any given time I've got a stack something like:
$pos
[0]='tagname'
[1]='0'
[2]='var'
And I want to concatenate those elements into a usable array reference, $arr[tagname][0][var], to do the assignment.
I've tried concatting the lot into a string and using that string as a variable variable, but that doesn't work. It's 2am and my mind is blank - any suggestions?