note 46256 deleted from ref.simplexml by aidan

From: Date: Wed, 22 Dec 2004 07:23:37 +0000
Subject: note 46256 deleted from ref.simplexml by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82154@lists.php.net to get a copy of this message
Note Submitter: ---- // 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();

« previous php.notes (#82154) next »