libertyct Posted August 8, 2008 Share Posted August 8, 2008 (edited) Hi, I just started working with the php XML DOM and need help getting around a simple task. i created my first xml file :-) <?xml version="1.0" encoding="ISO-8859-1"?> <hr> <person> <information status="active" > <firstname>firstname</firstname> <lastname>lastname</lastname> <age>99</age> </information> <employment> <employee>IBM</employee> <occupation>programmer</occupation> <level>intermmediate</level> </employment> </person> <person> <information status="active"> <firstname>firstname</firstname> <lastname>lastname</lastname> <age>99</age> </information> <employment> <employee>CBC</employee> <occupation>manager</occupation> <level>senior</level> </employment> </person> </hr> now i know how to loop through the file and print all elements but i am not sure how to go about printing specific elements. eg how i do it if i just wanted to print the persons age in the <information> node? i have attached a piece of my working-in-progress code below: $xmlDocument = new DOMDocument(); $xmlDocument->load("person.xml"); $xmlElement = $xmlDocument.documentElement.childNodes; for($i = 0 ; $i < count($xmlElement) ; $i++) { echo $xmlElement[$i].nodeName; } Edited July 18, 2017 by requinix substituting fake names/ages by poster's request Quote Link to comment https://forums.phpfreaks.com/topic/118800-print-xml-contents-noob/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Rather than using that extension, check out the SimpleXML extension. Much easier to work with for simple XML files. Quote Link to comment https://forums.phpfreaks.com/topic/118800-print-xml-contents-noob/#findComment-611707 Share on other sites More sharing options...
libertyct Posted August 8, 2008 Author Share Posted August 8, 2008 Rather than using that extension, check out the SimpleXML extension. Much easier to work with for simple XML files. well thanks, im actually going to work with SimpleXML later too, but i wanted to get a feel of both as well. Quote Link to comment https://forums.phpfreaks.com/topic/118800-print-xml-contents-noob/#findComment-611716 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.