PHP getDocNamespaces() 함수
예시
XML 문서의 루트에 선언된 네임스페이스를 반환합니다.
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3schools.com/ns">
<c:car id="1">Volvo</c:car>
<c:car id="2">BMW</c:car>
<c:car id="3">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces();
print_r($ns);
?>
정의 및 사용
getDocNamespaces() 함수는 XML 문서에 선언된 네임스페이스를 반환합니다.
통사론
SimpleXMLElement::getDocNamespaces(recursive, from_root)
매개변수 값
Parameter | Description |
---|---|
recursive | Optional. Specifies a Boolean value. If TRUE, all namespaces declared in document are returned. If FALSE, only namespaces declared in root node is returned. Default is FALSE |
from_root | Optional. Specifies a Boolean value. TRUE checks namespaces from the root of the XML document. FALSE checks namespaces under a child node. Default is TRUE |
기술적 세부 사항
반환 값: | 연관된 URI가 있는 네임스페이스 이름의 배열 |
---|---|
PHP 버전: | 5.1.2+ |
PHP 변경 로그: | PHP 5.4: from_root 매개변수가 추가되었습니다 . |
더 많은 예
예시
XML 문서에 선언된 모든 네임스페이스를 반환합니다.
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3schools.com/ns">
<c:car id="1">Volvo</c:car>
<c:car id="2">BMW</c:car>
<c:car id="3" a:country="Sweden" xmlns:a="http://w3schools.com/country">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces(TRUE);
var_dump($ns);
?>
❮ PHP SimpleXML 참조