How to use addChild in PHP

In this article I will explain how addChild function used in PHP.
  • 1411

addChild() Function

This function add a child element to a xml file.

Syntax

class SimpleXMLElement
{
string addChild(name,value,ns)
}


Example

XML Code

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tanya says</to>
<from> to Sachin</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

PHP Code

<html>
<body>
<?php
$xml = simplexml_load_file("D:\sachin\parse.xml");
$xml->body[0]->addChild("date", "1992-01-19");
foreach ($xml->body->children() as $child)
{
echo "Child node: " . $child . "<br />";
}
?>
</html>
</body>

Output

addChild-php.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.