spelltwister Posted August 13, 2006 Share Posted August 13, 2006 Hey all,I'm having a hard time finding any examples of parsing XML that has attributes.Here's the xml:<units> <persiancamp unit="infantry" number="8" owner="persian" ranged="0" /> <persiancamp unit="xerxes" number="1" owner="persian" ranged="0" /> <m1 unit="sInfantry" number="1" owner="persian" ranged="1" /><...></units>I have an array with all possible tag names and I need to be able to do something like this:$array = array('persiancamp','m1'...);for($i=0;$i<sizeof($array);$i++){ //CYCLE THROUGH XML FINDING IF TAGS MATCH CURRENT ARRAY VALUE, GATHER ALL ATTRIBUTE INFORMATION}Also, is this the most efficient way? Should I setup the XML like this:<persiancamp> <infantry number = '8' ranged ='0' /> <xerxes number = '1' ranged='0' /></persiancamp>OR<persiancamp> <infantry> <number>8</number> <ranged>0</ranged> </infantry> <xerxes> <number>1</number> <ranged>0</ranged> </xerxes></persiancamp>and use innertext attributes?Any help, or links to tutorials are much appreciated.Thanks!Mike Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 13, 2006 Share Posted August 13, 2006 What are you using to parse your XML? PHP's built in functions, or a seperate library? Additionally, if you are using PHP's functions, what version of PHP are you using, because they differ substantially.I generally use a seperate library because PHP's functions differs so much between versions. I recommend minixml (http://minixml.psychogenic.com/), as it is easy to use and is compatible with php 4 and 5. Quote Link to comment Share on other sites More sharing options...
spelltwister Posted August 14, 2006 Author Share Posted August 14, 2006 I should have mentioned that I'm using PHP 4.3.OMG! That thing is amazingly simple and easy to use. Thanks so much for letting me know about it! :-DMike Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.