note 91563 added to domdocument.createelement

From: Date: Wed, 17 Jun 2009 09:01:59 +0000
Subject: note 91563 added to domdocument.createelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-156955@lists.php.net to get a copy of this message
To create elements with attributes, <?php function createElement($domObj, $tag_name, $value = NULL, $attributes = NULL) { $element = ($value != NULL ) ? $domObj->createElement($tag_name, $value) : $domObj->createElement($tag_name); if( $attributes != NULL ) { foreach ($attributes as $attr=>$val) { $element->setAttribute($attr, $val); } } return $element; } $dom = new DOMDocument('1.0', 'utf-8'); $elm = createElement($dom, 'foo', 'bar', array('attr_name'=>'attr_value')); $dom->appendChild($elm); echo $dom->saveXML(); ?> outputs : <?xml version="1.0" encoding="utf-8"?> <foo attr_name="attr_value">bar</foo> ---- Server IP: 209.41.74.194 Probable Submitter: 212.174.133.164 ---- Manual Page -- http://www.php.net/manual/en/domdocument.createelement.php Edit -- https://master.php.net/note/edit/91563 Del: integrated -- https://master.php.net/note/delete/91563/integrated Del: useless -- https://master.php.net/note/delete/91563/useless Del: bad code -- https://master.php.net/note/delete/91563/bad+code Del: spam -- https://master.php.net/note/delete/91563/spam Del: non-english -- https://master.php.net/note/delete/91563/non-english Del: in docs -- https://master.php.net/note/delete/91563/in+docs Del: other reasons-- https://master.php.net/note/delete/91563 Reject -- https://master.php.net/note/reject/91563 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156955) next »