Get the child elements of the current element and output the name and data:
<?php
$bookxml = <<<XML
<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
</book>
</bookstore>
XML;
$xml = new SimpleXMLIterator($bookxml);
for( $xml->rewind(); $xml->valid(); $xml->next() ) {
foreach($xml->getChildren() as $name => $data) {
echo "The $name is '$data'";
echo "<br>";
}
}
?>
Run Example »
The getChildren() function returns the child elements of the current element.
SimpleXMLIterator::getChildren()
Return Value: | A SimpleXMLIterator object containing the children of the current element |
---|---|
PHP Version: | 5.0+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!