PHP Doku:: Adds new attribute node to element - domelement.setattributenode.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzXML-ManipulationDocument Object ModelThe DOMElement classDOMElement::setAttributeNode

Ein Service von Reinhard Neidl - Webprogrammierung.

The DOMElement class

<<DOMElement::setAttribute

DOMElement::setAttributeNodeNS>>

DOMElement::setAttributeNode

(PHP 5)

DOMElement::setAttributeNodeAdds new attribute node to element

Beschreibung

DOMAttr DOMElement::setAttributeNode ( DOMAttr $attr )

Adds new attribute node attr to element.

Parameter-Liste

attr

The attribute node.

Rückgabewerte

Returns old node if the attribute has been replaced or NULL.

Fehler/Exceptions

DOM_NO_MODIFICATION_ALLOWED_ERR

Raised if the node is readonly.

Siehe auch


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
karvjorm at users.sourceforge.net
3.03.2007 1:01
$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>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)