I am getting XML from a web service, and am having a hard time maintaining the order of the XML elements that are displayed.
Here is a snippet:
<Blocks>
<Block>
<BlockElements>
<Question QuestionID="QID59" />
<PageBreak />
<Question QuestionID="QID3" />
<Question QuestionID="QID1" />
<PageBreak />
<Question QuestionID="QID2" />
<PageBreak />
<Question QuestionID="QID47" />
</BlockElements>
</Block>
<Block>
<BlockElements>
<Question QuestionID="QID6" />
<PageBreak />
<Question QuestionID="QID8" />
<Question QuestionID="QID49" />
<Question QuestionID="QID45" />
<Question QuestionID="QID50" />
<PageBreak />
<Question QuestionID="QID9" />
<Question QuestionID="QID10" />
<PageBreak />
<Question QuestionID="QID11" />
<Question QuestionID="QID12" />
<PageBreak />
<Question QuestionID="QID13" />
<PageBreak />
<Question QuestionID="QID14" />
<PageBreak />
<Question QuestionID="QID15" />
<PageBreak />
<Question QuestionID="QID16" />
<PageBreak />
<Question QuestionID="QID17" />
<PageBreak />
<Question QuestionID="QID18" />
<Question QuestionID="QID19" />
<PageBreak />
<Question QuestionID="QID20" />
<Question QuestionID="QID21" />
<PageBreak />
<Question QuestionID="QID22" />
<Question QuestionID="QID23" />
</BlockElements>
</Block>
</Blocks>
The web service uses the empty elements and (elements without closing tags). The order of these elements within the BlockElements tags is crucial- it defines the layout of a form. When I turn this XML into a PHP object using a SimpleXmlElement, this is what I get:
SimpleXMLElement Object
(
[Block] => Array
(
[0] => SimpleXMLElement Object
(
[BlockElements] => SimpleXMLElement Object
(
[Question] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[QuestionID] => QID59
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[QuestionID] => QID3
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[QuestionID] => QID1
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[QuestionID] => QID2
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[QuestionID] => QID47
)
)
)
[PageBreak] => Array
(
[0] => SimpleXMLElement Object
(
)
[1] => SimpleXMLElement Object
(
)
[2] => SimpleXMLElement Object
(
)
)
)
)
....
The Question elements and PageBreak elements are separated into arrays, and their order is lost. Any advice on maintaining the order of these elements? I am not committed to using SimpleXmlElement- I'll use whatever works. Thanks!