Solved

append child to simple_xml_string

Posted on 2010-08-23
3
527 Views
Last Modified: 2013-12-13
Is there a way to append a child to a xml string.

For example, I have:

$Element = simplexml_load_string('<tree></tree>');

I want to append a child to the node "tree".
0
Comment
Question by:pillmill
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
Comment Utility
<?php

$Element = simplexml_load_string('<tree></tree>');
$Element->addChild("fred");

echo htmlentities( $Element->asXml() );

0
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
This will not only add the child node, but it will give it some content.
<?php // RAY_temp_pillmill.php

$obj = simplexml_load_string('<tree></tree>');
$obj->addChild("fred");
$obj->fred = 'Flintstone';

echo htmlentities( $obj->asXml() );

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now