PHP children() 함수
예시
메모 노드의 자식 찾기:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
정의 및 사용
children() 함수는 지정된 노드의 자식을 찾습니다.
통사론
SimpleXMLElement::children(ns, prefix)
매개변수 값
Parameter | Description |
---|---|
ns | Optional. Specifies an XML namespace |
prefix | Optional. A Boolean value. If TRUE ns is regarded as a prefix. If FALSE ns is regarded as a namespace URL. Default is FALSE |
기술적 세부 사항
반환 값: | SimpleXMLElement 객체를 반환합니다. |
---|---|
PHP 버전: | 5.0+ |
PHP 변경 로그: | PHP 5.2: 선택적 접두사 매개변수 추가 |
더 많은 예
예시
body 노드의 자식 찾기:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Do
not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
❮ PHP SimpleXML 참조