Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : DOM Functions : DOMElement->setIdAttribute()

DOMElement->setIdAttribute()

Declares the attribute specified by name to be of type ID ()

DOMElement {
  void setIdAttribute(string name,
                      bool isId);

}

Declares the attribute name to be of type ID.

Parameters

name

The name of the attribute.

isId

Set it to TRUE if you want name to be of type ID, FALSE otherwise.

Return Values

No value is returned.

Errors/Exceptions

DOM_NO_MODIFICATION_ALLOWED_ERR

Raised if the node is readonly.

DOM_NOT_FOUND

Raised if name is not an attribute of this element.

Code Examples / Notes » dom_domelement_setidattribute

elmarhinz

The second parameter doesn't exactly do, what you would expect. So use the method with care.
If it is TRUE the method works like a switch.
If it is FALSE the method turns ID setting off.
A unit test demonstrates the exact behaviour:
   public function testSetIdAttribute() {
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertType('DOMElement', $this->dom->getElementById('testChild'));
$this->assertNotNull($this->dom->getElementById('testChild'));
     // TRUE switches between on and off, while false turns it off.
$this->child->setIdAttribute('id', TRUE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNotNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', TRUE);
$this->assertNotNull($this->dom->getElementById('testChild'));
     // FALSE turns off and not on any more.
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
$this->child->setIdAttribute('id', FALSE);
$this->assertNull($this->dom->getElementById('testChild'));
   }


Change Language


Follow Navioo On Twitter
DOMAttr->__construct()
DOMAttr->isId()
DOMCharacterData->appendData()
DOMCharacterData->deleteData()
DOMCharacterData->insertData()
DOMCharacterData->replaceData()
DOMCharacterData->substringData()
DOMComment->__construct()
DOMDocument->__construct()
DOMDocument->createAttribute()
DOMDocument->createAttributeNS()
DOMDocument->createCDATASection()
DOMDocument->createComment()
DOMDocument->createDocumentFragment()
DOMDocument->createElement()
DOMDocument->createElementNS()
DOMDocument->createEntityReference()
DOMDocument->createProcessingInstruction()
DOMDocument->createTextNode()
DOMDocument->getElementById()
DOMDocument->getElementsByTagName()
DOMDocument->getElementsByTagNameNS()
DOMDocument->importNode()
DOMDocument->load()
DOMDocument->loadHTML()
DOMDocument->loadHTMLFile()
DOMDocument->loadXML()
DOMDocument->normalizeDocument()
DOMDocument->registerNodeClass()
DOMDocument->relaxNGValidate()
DOMDocument->relaxNGValidateSource()
DOMDocument->save()
DOMDocument->saveHTML()
DOMDocument->saveHTMLFile()
DOMDocument->saveXML()
DOMDocument->schemaValidate()
DOMDocument->schemaValidateSource()
DOMDocument->validate()
DOMDocument->xinclude()
DOMDocumentFragment->appendXML()
DOMElement->__construct()
DOMElement->getAttribute()
DOMElement->getAttributeNode()
DOMElement->getAttributeNodeNS()
DOMElement->getAttributeNS()
DOMElement->getElementsByTagName()
DOMElement->getElementsByTagNameNS()
DOMElement->hasAttribute()
DOMElement->hasAttributeNS()
DOMElement->removeAttribute()
DOMElement->removeAttributeNode()
DOMElement->removeAttributeNS()
DOMElement->setAttribute()
DOMElement->setAttributeNode()
DOMElement->setAttributeNodeNS()
DOMElement->setAttributeNS()
DOMElement->setIdAttribute()
DOMElement->setIdAttributeNode()
DOMElement->setIdAttributeNS()
DOMEntityReference->__construct()
DOMImplementation->__construct()
DOMImplementation->createDocument()
DOMImplementation->createDocumentType()
DOMImplementation->hasFeature()
DOMNamedNodeMap->getNamedItem()
DOMNamedNodeMap->getNamedItemNS()
DOMNamedNodeMap->item()
DOMNode->appendChild()
DOMNode->cloneNode()
DOMNode->hasAttributes()
DOMNode->hasChildNodes()
DOMNode->insertBefore()
DOMNode->isDefaultNamespace()
DOMNode->isSameNode()
DOMNode->isSupported()
DOMNode->lookupNamespaceURI()
DOMNode->lookupPrefix()
DOMNode->normalize()
DOMNode->removeChild()
DOMNode->replaceChild()
DOMNodelist->item()
DOMProcessingInstruction->__construct()
DOMText->__construct()
DOMText->isWhitespaceInElementContent()
DOMText->splitText()
DOMXPath->__construct()
DOMXPath->evaluate()
DOMXPath->query()
DOMXPath->registerNamespace()
dom_import_simplexml
eXTReMe Tracker