Hàm getNamespaces() của PHP
Ví dụ
Trả về tất cả các không gian tên được sử dụng trong tài liệu XML:
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="https://example.com.vn/ns" xmlns:a="https://example.com.vn/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);
?>
Chạy ví dụ »Định nghĩa và cách sử dụng
Hàm getNamespaces() trả về các không gian tên được sử dụng trong tài liệu XML.
Cú pháp
SimpleXMLElement::getNamespaces( recursive )
Giá trị tham số
Parameter | Description |
---|---|
recursive | Optional. Specifies a Boolean value. If TRUE, all namespaces used in document are returned. If FALSE, only namespaces used in root node is returned. Default is FALSE |
Chi tiết kỹ thuật
Giá trị trả về: | Một mảng tên không gian tên với các URI liên quan của chúng |
---|---|
Phiên bản PHP: | 5.1.2+ |
❮ Tham khảo PHP SimpleXML