PHP의 getNamespaces () 함수
예
네임 스페이스를 사용하여 XML 문서를 반환합니다 :
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3cschool.cc/ns" xmlns:a="http://w3cschool.cc/country">
<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->getNamespaces(true);
var_dump($ns);
?>
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3cschool.cc/ns" xmlns:a="http://w3cschool.cc/country">
<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->getNamespaces(true);
var_dump($ns);
?>
»인스턴스를 실행
정의 및 사용
getNamespaces () 함수는 문서에서 사용되는 XML 네임 스페이스를 반환합니다.
문법
getNamespaces( recursive );
参数 | 描述 |
---|---|
recursive | 可选。规定一个布尔值。如果值为 TRUE,则返回所有父节点和子节点中声明的所有命名空间。如果值为 FALSE,则只返回根节点中声明的命名空间。默认是 FALSE。 |
기술 세부 사항
반환 값 : | 그것은 URI와 관련된 네임 스페이스 이름의 배열을 반환합니다. |
---|---|
PHP 버전 : | 5.1.2+ |
PHP SimpleXML을 참조 설명서