Funzione getNamespace() PHP
Definizione e uso
La funzione getNamespace() recupera le namespace utilizzate nel documento XML.
Se ha successo, la funzione restituisce un array di namespace (connessi agli URL associati). Se fallisce, restituisce false.
Sintassi
class SimpleXMLElement { string getNamespace(recursive) }
Parametro | Descrizione |
---|---|
recursive | Opzionale. Specifica se restituire tutte le namespace utilizzate nei nodi figli e padre. Il valore predefinito è false. |
Esempio
File XML:
<?xml version="1.0" encoding="ISO-8859-1"?> <note xmlns:b="http://www.codew3c.com/example/"> <to>George</to> <from>John</from> <heading>Promemoria</heading> <b:body>Non dimenticare l'incontro!</b:body> </note>
Codice PHP:
<?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); } print_r($xml->getNamespaces()); ?>
Output simile a:
Array ( [b] => http://www.codew3c.com/example/ )