Create an XML Structure with PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 !








PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux