Jump to content

Displaying Xml In A Nice Format


3dhomejoe
 Share

Recommended Posts

Hello,Ive got this xml document that gets updated every 48 hours and Im trying to make it display in a nice format for a website and the code that im using does not display all of it.My code

<?php$xml = simplexml_load_file("myguild.xml");echo $xml->getName() . "<br />";foreach($xml->children() as $child)  {  echo $child->getName() . ": " . $child . "<br />";  }?>

and what it spits out is

guilddetails:members:
and this is the xml file, sorry the formatting got messed up
<guild>−<details><id>2</id><name>Testname</name><server>Testserver</server></details>−<members>−<member><id>328</id><name>				testmember	</name><guildRank>				Leader	</guildRank><level>																56 							</level><class>						Templar	</class><artisanClass>						Weaponsmith	</artisanClass><artisanLevel>																45 							</artisanLevel><secondaryTradeskillClass>				none	</secondaryTradeskillClass><secondaryTradeskillLevel>																0 							</secondaryTradeskillLevel></member></guild>

Can anyone help me please?Thanks3dhomejoe

Link to comment
Share on other sites

I think the problem is that echo-ing an element doesn't give you the text contents of all of its descendats.Either loop over the child's children, or use asXML(), like:

foreach($xml->children() as $child)  {  echo $child->getName() . ": " . $child->asXML() . "<br />";  }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...