Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php pear xml_serializer question

Status
Not open for further replies.

richardko

Programmer
Jun 20, 2006
127
US
Hi,
I am trying to create a xml file using the XML_serializer class and needed some help.
The file i am trying to create looks like this:
<?xml version="1.0" encoding="utf-8"?>
<MainTag>
<header>
This is the data for header tag
</header>
<product>
<productID>
1
</productID>
</product>
<product>
<productID>
2
</productID>
</product>
</MainTag>

I am trying to create this using mysql since I have a lot of product ID but have a problem creating the header. The header appears separate from the rest of the <product> tags.
Any idea how to create this?
 
If the data in the header tag is also in the database, you'll probably need two queries. This is easiest logically. Pseudocode:

Code:
query-for-header-data;
write-header;
query-for-product-data;
foreach product
   write <product>\n<productID>\n;
   write productID;
   write </productID>\n</product>\n;
write-footer;

If they use the same exact query, you can build a String with all the data for the product tags while you're writing the header tags.

Code:
write-down-to-header-data;
query-for-data;
foreach product
   write-header-data-for-product ;
   mystring .= <product>\n<productID>\n . productID;
   mystring .= </productID>\n</product>\n;
write-end-header ;
write mystring;
write-footer;
 
Thanks for the advice,
I ended up creating another method to create the XML file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top