note 18302 deleted from function.domxml-new-xmldoc by nlopess

From: Date: Fri, 25 Jun 2004 18:06:01 +0000
Subject: note 18302 deleted from function.domxml-new-xmldoc by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71687@lists.php.net to get a copy of this message
Note Submitter: emanuel@elogica.com.br ---- Hi there, I´ve made this code bellow. I think it´s a good exemple of creating a new XML file, nodes and how to set attributes. Hugs, Emanuel ............... function make_node($parent,$name,$content) { // Adds a new child node to parent node $parent->new_child($name,$content); // Return the newly added child as a reference return $parent->last_child(); } // ................ // XML Process $varVersion = date("YmdHms"); // Create a new xml and add a root node $doc = domxml_new_xmldoc("1.0"); $xmlMainNode = $doc->add_root("DATAPACKET"); $xmlMainNode->set_attribute("version",$varVersion); // Create the subnodes $xmlMetaDataNode = make_node($xmlMainNode,"METADATA",""); $xmlFieldSDataNode = make_node($xmlMetaDataNode,"FIELDS",""); // Set the Fields name on the XML $xmlSubFieldDataNode = make_node($xmlFieldSDataNode,"FIELD",""); $xmlSubFieldDataNode->set_attribute("attrname","Version"); $xmlSubFieldDataNode->set_attribute("fieldtype","string"); $xmlSubFieldDataNode->set_attribute("WIDTH","50"); $xmlSubFieldDataNode = make_node($xmlFieldSDataNode,"FIELD",""); $xmlSubFieldDataNode->set_attribute("attrname","Date_Release"); $xmlSubFieldDataNode->set_attribute("fieldtype","string"); $xmlSubFieldDataNode->set_attribute("WIDTH","50"); // Set the PARMS node $xmlParamNode = make_node($xmlMetaDataNode,"PARAMS",""); $xmlParamNode->set_attribute("DEFAULT_ORDER","1"); $xmlParamNode->set_attribute("PRIMARY_KEY","1"); $xmlParamNode->set_attribute("LCID","1033"); // Set the contents of the data base $xmlRowDataNode = make_node($xmlMainNode,"ROWDATA",""); $varVersion = "1.0"; $varDate = "2002-01-17"; $xmlRowNode = make_node($xmlRowDataNode,"ROW",""); $xmlRowNode->set_attribute("Version",$varVersion); $xmlRowNode->set_attribute("Date_Release",$varDate); $xmlRowNode->set_attribute("Download",$varDownloadA); $varXmlFile = $doc->dumpmem(); // Add any encoding item, instead PHP don´t have a function to do it $varXmlFile = str_replace('version="1.0"','version="1.0" encoding="ISO-8859-1" standalone="yes"',$varXmlFile); // Creates the XML file $fp = fopen("test.xml", "w"); fwrite($fp, $varXmlFile); fclose($fp);

« previous php.notes (#71687) next »