Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

append child to simple_xml_string

Posted on 2010-08-23
3
Medium Priority
?
598 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 2000 total points
ID: 33506521
<?php

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

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

0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 33506531
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33511631
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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