Jump to content

Print XML Contents (noob)


libertyct

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.