Create an XML Structure with PHP
Posted: Tue Jan 10, 2006 10:52 am
Hello to all...
I'm using a method which construct an XML:
This function creates an XML like this:
I WANT TO BE CREATED THE FOLLOWING STRUCTURE (GROUPED TAGS BASED ON
category name):
I'm confused on how I must change the method to implement this.
HELP !
I'm using a method which construct an XML:
Code: Select all
function convertToXML($sql, $filename) {
$result = $this->recordSet->select($sql);
$this->xml->create_root();
$fh = fopen( '../main.xml', 'r' );
$this->xml->read_file_handle( $fh );
$this->xml->roottag->add_subtag('filelist', array() );
while ($list_result = $this->recordSet->setRow($result)) {
$this->xml->roottag->curtag->add_subtag('category', array('name'
=> $this->recordSet->cdata = $list_result[0], 'description' => '',
'thumb' => '', 'allowed' => 'true') );
$tag = &$this->xml->roottag->curtag;
$this->xml->roottag->curtag->curtag->add_subtag('image',
array('filename'=> $this->recordSet->cdata = $list_result[5],
'productname'=> $this->recordSet->cdata = $list_result[1],
'productdescription'=> $this->recordSet->cdata = $list_result[2],
'productsubtitle'=> $this->recordSet->cdata = $list_result[3],
'productprice'=> $this->recordSet->cdata = $list_result[4]));
}
$xml_file = fopen($filename, "w" );
$this->xml->write_file_handle( $xml_file );
}Code: Select all
<filelist>
<category name="frontrunner" description="" thumb="" allowed="true">
<image filename="frontrunner_bg.jpg" productname=""
productdescription="" productsubtitle="" productprice=""/>
</category>
<category name="frontrunner" description="" thumb="" allowed="true">
<image filename="fr_lydia.jpg" productname="Lydia zip knit / Aldora
skirt" productdescription="" productsubtitle="" productprice=""/>
</category>
<category name="oldschool" description="" thumb="" allowed="true">
<image filename="oldschool2_bg.jpg" productname=""
productdescription="" productsubtitle="" productprice=""/>
</category>
<category name="oldschool" description="" thumb="" allowed="true">
<image filename="os_atlanta.jpg" productname="Atlanta zip jacket"
productdescription="" productsubtitle="" productprice=""/>
</category>
</filelist>category name):
Code: Select all
<filelist>
<category name="frontrunner" description="" thumb="" allowed="true">
<image filename="frontrunner_bg.jpg" productname=""
productdescription="" productsubtitle="" productprice=""/>
<image filename="fr_lydia.jpg" productname="Lydia zip knit / Aldora
skirt" productdescription="" productsubtitle="" productprice=""/>
</category>
<category name="oldschool" description="" thumb="" allowed="true">
<image filename="oldschool2_bg.jpg" productname=""
productdescription="" productsubtitle="" productprice=""/>
<image filename="os_atlanta.jpg" productname="Atlanta zip jacket"
productdescription="" productsubtitle="" productprice=""/>
</category>
</filelist>I'm confused on how I must change the method to implement this.
HELP !