Viobbyhoxi
New Member
I'm trying to make php script that draws an image from XML set of commands. Here's an example of XML:\[code\]<image w="100" h="100"> <line x1="0" y1="0" x2="99" y2="99" border="3" color="#FF0000" /> <ellipse x="50" y="50" w="100" color="#0000FF" fill="#00FF00" /> <polygon fill="#FFFF00" color="#FFFF00"> <coord x="24" y="25" /><coord x="44" y="25" /><coord x="44" y="37" /><coord x="24" y="37" /> </polygon> <text x="25" y="25" font="2">FER</text> <img src="http://www.fer.hr/_pub/logofer.gif" x="50" y="50" w="40" h="40" /> <line x1="0" y1="0" x2="88" y2="88" border="3" color="#FF0000" /></image>\[/code\]My idea was to store all of elements that needs to be rendered inside an array from where they'd be rendered in order as they were defined in xml.Problem is, if I have one command, like "line" appear multiple times, I than get an object line that contains array with properties of line one and line two and that doesn't allow me to know whether line 1 came before ellipse, or after it or if it's before img or after it.I'm using \[code\]simplexml_load_string\[/code\] to parse xml. Is there solution to this mixed order? Can I maybe get all elements inside image elements stored as array with objects or something?Here's example of problem and var_dump:\[code\]<?xml version="1.0" encoding="UTF-8"?><image w="100" h="100"><line x1="0" y1="0" x2="99" y2="99" border="3" color="#FF0000" /><ellipse x="50" y="50" w="100" color="#0000FF" fill="#00FF00" /><line x1="0" y1="0" x2="99" y2="99" border="3" color="#FF0000" /></image>\[/code\]You can notice (in the \[code\]var_dump\[/code\]) that there's no way to find out if line1 came before ellipse or after.[EDIT] I have to little reputation so I can't answer my question in next 8 hours. Anyway, I've found out I can do the following in order to get the elements in the correcct order:\[code\]foreach($xml->children() as $name => $child){ echo "$name = "; var_dump($child); echo "<br />";}\[/code\]