libertyct Posted August 8, 2008 Share Posted August 8, 2008 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; } 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. 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. Link to comment https://forums.phpfreaks.com/topic/118800-print-xml-contents-noob/#findComment-611716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.