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;

}

Edited by requinix
substituting fake names/ages by poster's request
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.