freelanceprogrammers.org Forum Index » PHP

Create an XML Structure with PHP


View user's profile Post To page top
alavastros Posted: Tue Jan 10, 2006 10:18 pm


Joined: 10 Jan 2006

Posts: 1
Create an XML Structure with PHP
Hello to all...

I`m using a method which construct an XML:

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 );
}

This function creates an XML like this:

<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>

I WANT TO BE CREATED THE FOLLOWING STRUCTURE (GROUPED TAGS BASED ON
category name):
<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 !
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help