PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SimpleXMLElement->getNamespaces()> <SimpleXMLElement->getDocNamespaces()
Last updated: Fri, 20 Jun 2008

view this page in

SimpleXMLElement->getName()

(PHP 5 >= 5.1.3)

SimpleXMLElement->getName() — Récupère le nom d'un élément XML

Description

SimpleXMLElement
string getName ( void )

Récupère le nom d'un élément XML.

Valeurs de retour

La méthode getName retourne un nom sous la forme de chaîne de caractères d'une balise XML référencé par l'objet SimpleXMLElement.

Exemples

Exemple #1 Récupère les noms des éléments XML

<?php

$sxe 
= new SimpleXMLElement($xmlstr);

echo 
$sxe->getName() . "\n";

foreach (
$sxe->children() as $child)
{
    echo 
$child->getName() . "\n";
}

?>



add a note add a note User Contributed Notes
SimpleXMLElement->getName()
Anonymous
18-Mar-2008 08:32
The bogus Behaviour reported in the last two comments was for me with version 5.2.x, after an upgrade to PHP 5.2.5 this was not the case any longer. I could not find any relating bug under bugs.php.net so maybe this was just a fix made.
Anonymous
08-Mar-2008 08:11
In Response to:

Some unexpected behaviour noticed:
<?php
echo $root->parent->child->getName();
?>

"child" is expected, although "parent" is returned

My Suggestion is to use

<?php
echo $root->parent[0]->child[0]->getName();
?>

Instead. I dunno why, but this works.
Anonymous
03-Jan-2008 05:40
$root = new SimplexmlElement("<root><parent><child/></parent></root>");
foreach($root->parent->children() as $child){
    print "</br>".$child->getName();
}

//This will return the child though
m0sh3 at Hotmail dot com
02-Jul-2007 12:25
Some unexpected behaviour noticed:

<?php

$root
= new SimplexmlElement("<root><parent><child/></parent></root>");
echo
$root->parent->child->getName();
?>

"child" is expected, although "parent" is returned

 
show source | credits | sitemap | contact | advertising | mirror sites