note 46256 added to ref.simplexml

From: Date: Mon, 04 Oct 2004 18:16:46 +0000
Subject: note 46256 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-77996@lists.php.net to get a copy of this message
// The only way I found to add elements (through dom) function & sXmlAddChildNode( $simpleXml, $xpathParentNode, $childNodeName, $childNodeValue='' ){ $dom = new DomDocument(); $dom->loadXML( $simpleXml->asXml() ); $xpath =& new DomXPath( $dom ); $parent =& $xpath->query( $xpathParentNode ); $elem =& $dom->createElement( $childNodeName, $childNodeValue ); $parent->item(0)->appendChild( $elem ); return simplexml_import_dom( $dom ); } // usage: $xml = simplexml_load_string( '<?xml version="1.0" standalone="yes"?><root><parenttag></parenttag></root>' ); $xml = sXmlAddChildNode( $xml, "//parenttag", 'childtag', 'xxxyyy' ); echo $xml->asXml(); ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46256 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46256&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46256&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77996) next »