How to use children in PHP

In this article I will explain how children function used in PHP.
  • 1394

children() Function

This function gets the child nodes from specified XML node.

Syntax

class SimpleXMLElement
{
string children(ns,is_prefix)
}

 

 Parameter  Description
 ns  Optional
 is_prefix  Optional

Example

XML file

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


PHP Code

<html>
<body>
<?php
$xml = simplexml_load_file("D:\sachin\parse.xml");
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br />";
}
?>
</html>
</body>

Output

Children-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.