DOMElement::setAttributeNode

(PHP 5, PHP 7, PHP 8)

DOMElement::setAttributeNodeAdiciona um novo nó de atributo ao elemento

Descrição

public DOMElement::setAttributeNode(DOMAttr $attr): DOMAttr|null|false

Adiciona um novo nó de atributo attr ao elemento. Se um atributo com o mesmo nome já existir no elemento, esse atributo será substituído por attr.

Parâmetros

attr

O nó de atributo.

Valor Retornado

Retorna o atributo antigo se tiver sido substituído ou null se não houver atributo antigo. Se ocorrer um erro de DOM_WRONG_DOCUMENT_ERR, e strictErrorChecking for false, false será retornado.

Erros/Exceções

DOM_WRONG_DOCUMENT_ERR

Gerado se attr pertencer a um documento diferente do elemento.

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 1 note

up
-1
karvjorm at users.sourceforge.net
18 years ago
$dom = new DomDocument('1.0','iso-8859-15');$ht_ml = $dom->appendChild($dom->createElement('html'));$he_ad = $ht_ml->appendChild($dom->createElement('head'));$tit_le= $he_ad->appendChild($dom->createElement('title'));$tit_le->appendChild($dom->createTextNode('DOMAttr test'));$me_ta = $he_ad->appendChild(new DOMElement('meta'));$me_ta->setAttributeNode(new DOMAttr('name', 'Description'));$me_ta->setAttributeNode(new DOMAttr('content', 'example'));$me_ta = $he_ad->appendChild(new DOMElement('meta'));$me_ta->setAttributeNode(new DOMAttr('name', 'Author'));$me_ta->setAttributeNode(new DOMAttr('content', 'karvjorm'));Result:<?xml version="1.0" encoding="iso-8859-15"?><html>  <head>    <title>DOMAttr test</title>    <meta name="Description" content="example"/>    <meta name="Author" content="karvjorm"/>  </head>
To Top