Re: [sql2xml] Define attributes and commented fields ?
| From: | Daniel García | Date: | Fri, 10 Sep 2004 10:25:23 +0000 |
| Subject: | Re: [sql2xml] Define attributes and commented fields ? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14485@lists.php.net to get a copy of this message | ||
Thanks Octavi for your help !
But I think that will render something like
<?xml version="1.0"?>
<root>
<result>
<row>
<ID>12</ID>
<DESCRIPTION>Description of item 12</DESCRIPTION>
</row>
</result>
</root>
instead of what I need:
<?xml version="1.0"?>
<root>
<result>
<row>
<DESCRIPTION ID="12">Description of item 12</DESCRIPTION>
</row>
</result>
</root>
-- Daniel
Octavi Fors wrote:
Daniel, I was in the need of the same solution some time ago. Thanks to help of some guys in this list I could get started. Basically, I'm using SQL2XML and DB packages in PEAR. Below there is a draft a of script which makes use of them. Hope it helps. Bye, Octavi. ****************************************************** Octavi Fors Universitat de Barcelona. ?rea de Tecnologies. Aplicacions. mailto:ofors@ub.edu ******************************************************* <?php $db=conecta_DB(); $sql ="select ID,DESCRIPTION from TABLE"; $xmlstring=sql2xml($sql,"TABLE"); $ftarget=fopen('sql2xml.xml','w') or die ("Can't write file"); fwrite ($ftarget,$xmlstring); fclose($ftarget); echo "Done!"; desconecta_DB ($db); # ----------------- function sql2xml ($sentecia_sql,$nameResult) # ----------------- { global $db;-- ===================================== Daniel García http://www.quintopino.com =====================================require_once 'DB.php'; // require_once 'XML/sql2xml.php'; require_once 'XML/XML_sql2xml-0.3.2/sql2xml.php';$sql2xmlclass = new xml_sql2xml($db,"");$options = array("nested"=>False,"tagNameRow"=>"proposta","tagNameResult"=>$nameResult); $sql2xmlclass->SetOptions($options);if(is_array($sentecia_sql)) { foreach($sentecia_sql as $sql) { $sql2xmlclass->add($sql); } } else { $sql2xmlclass->add($sentecia_sql); }$xmlstring=$sql2xmlclass->getxml(); // $xmlstring = $sql2xmlclass->getxml($result);return $xmlstring;} ?> On Fri, 10 Sep 2004, [ISO-8859-1] Daniel Garc?a wrote:Hello all, I'm in the process of creating code to export the data in a table to an xml file, but instead of transforming all the fetched DB fields into elements, I need to parse some DB fields into attributes, and others as comments. For example, the DB row is: +----------+---------------------+-----------+--------+---------+------------+----------+-------------+| textID | date | pageID | weight | visible | notes | text_es | text_en | +----------+---------------------+-----------+--------+---------+------------+----------+-------------+ | 430 | 2004-09-09 18:11:28 | 1 | 10 | 1 | Main screen| Volver | | +----------+---------------------+-----------+--------+---------+------------+----------+-------------+<?xml version="1.0"?> <root><result> <row> <!-- Main screen --> <text textID=430>Volver</text> </row> </result></root> That is, convert the "notes" field into a comment line, and use textID as an attribute. This way, I can pass the generated xml file to a translator, who will be able to import it into a Translation tool and work only on the original text. Any help / hint will be appreciated. TIA -- Daniel -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php