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

search for in the

DOMElement::removeAttribute> <DOMElement::hasAttribute
Last updated: Fri, 03 Oct 2008

view this page in

DOMElement::hasAttributeNS

(No version information available, might be only in CVS)

DOMElement::hasAttributeNS Vérifie si un attribut existe

Description

bool DOMElement::hasAttributeNS ( string $namespaceURI , string $localName )

Vérifie si un attribut dans l'espace de noms namespaceURI nommé localName existe en tant que membre de l'élément.

Liste de paramètres

namespaceURI

L'URI de l'espace de noms.

localName

Le nom local.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.



add a note add a note User Contributed Notes
DOMElement::hasAttributeNS
chad dot retz at gmail dot com
11-May-2008 09:38
This does not work as expected (at least on 5.2.5) with attributes in the default namespace. For instance:

<?php
$dom
= new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><element xmlns="testns" attr="testval" />');
var_dump($dom->documentElement->hasAttributeNS('testns', 'attr'));
?>

returns bool(false) whereas:

<?php
$dom
= new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><element xmlns:ns1="testns" ns1:attr="testval" />');
var_dump($dom->documentElement->hasAttributeNS('testns', 'attr'));
?>

returns bool(true). NULL does work properly in the namespaceURI parameter, so changing my initial example to:

<?php
$dom
= new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><element xmlns="testns" attr="testval" />');
var_dump($dom->documentElement->hasAttributeNS(NULL, 'attr'));
?>

returns bool(true) as expected. Or even better for when you don't know whether the NS will be default:

<?php
$dom
= new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><element xmlns="testns" attr="testval" />');
var_dump($dom->documentElement->hasAttributeNS(
   
is_null($dom->documentElement->lookupPrefix('testns')) ? NULL : 'testns', 'attr'));
?>

DOMElement::removeAttribute> <DOMElement::hasAttribute
Last updated: Fri, 03 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites