SimpleXMLElement

This is part of PHP core so no installation is required. This extension can be checked by using phpinfo().

Example 1 generate XML data

<?Php
header('Content-Type: text/xml');
$e = new SimpleXMLElement('<detils/>');


    $add = $e->addChild('address');
    $add->addChild('door_no', "Door_No: Abcd");
    $add->addChild('Street', "Street NO: 123 Abcd");

print($e->asXML());
?>
Output is here
<detils>
<address>
<door_no>Door_No: Abcd</door_no>
<Street>Street NO: 123 Abcd</Street>
</address>
</detils>

Example 2 generate XML by looping

<?Php
header('Content-Type: text/xml');
$e = new SimpleXMLElement('<detils/>');

for ($i = 1; $i <= 4; ++$i) {
    $add = $e->addChild('address');
    $add->addChild('door_no', "Door_No $i");
    $add->addChild('Street', "Street NO $i");
}
print($e->asXML());
?>
Output is here
<detils>
<address>
<door_no>Door_No 1</door_no>
<Street>Street NO 1</Street>
</address>
<address>
<door_no>Door_No 2</door_no>
<Street>Street NO 2</Street>
</address>
<address>
<door_no>Door_No 3</door_no>
<Street>Street NO 3</Street>
</address>
<address>
<door_no>Door_No 4</door_no>
<Street>Street NO 4</Street>
</address>
</detils>


plus2net.com




Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer