尋找note 節點的子節點:
<?php$note=<<<XML<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</ body></note>XML;$xml=simplexml_load_string($note);foreach ($xml->children() as $child) { echo "Child node: " . $child . "<br>"; }?>children() 函數尋找指定節點的子節點。
children( ns,is_prefix );
參數 | 描述 |
---|---|
ns | 可選。規定一個XML 命名空間。 |
is_prefix | 可選。規定一個布林值。如果值為TRUE,則ns是前綴。如果值為FALSE,則ns是命名空間URL。 |
傳回值: | 傳回一個SimpleXMLElement 物件。 |
---|---|
PHP 版本: | 5.0.1+ |
PHP 更新日誌: | 新增了is_prefix參數。 |
尋找body 節點的子節點:
<?php$note=<<<XML<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body><span>Important!</span> Don 't forget me this weekend!</body></note>XML;$xml=simplexml_load_string($note);foreach ($xml->body[0]->children() as $child) { echo "Child node: " . $child . "<br>"; }?>