• 0

Export database data to XML, with a twist


Question

I need to export data to some XML (I can decide on the criteria). I guess nothing to do with sales, but it's easiest analogy I could find:

I have a database table, and each row is a sold item. Colums are stuff like date, item part no. and customer no. (the purchaser).

I want to export data to XML, but I don't want a new root element per sale, I want one per item part no, like this:

<item>
	<partno>123123</partno>
	<buyers>
		<customer>123123</customer>
		<customer>999999</customer>
		<customer>912333</customer>
	</buyers>
</item>

So what I have is every sale (so there are many rows with the same part no.), but I want one XML element per item, and the customers listed as children. I don't have much experience with databases, but since every item has a different number of buyers,.. it's different than having table entries with 'fixed' columns.

Is there an "easy" way to do this (perhaps by means of PHP and querying a mysql database) or would I have to program it on PHP and make conditional statements such as "if the part no. already exists, just add a "customer" child).

I just need to be pointed in the right direction...

thanks in advance

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

What's the database? What language do you want the programming done in?

I guess PHP and MySQL would do, I could probably use dom_xml stuff.

I guess if I was actually in sales, I would have a separate database a row pert item no. So if I'm not mistaken, I could iterate.. for each item in the items database, find me every row in the 'sales' database that has a matching 'part no'. Then I could process the result and populate the XML thing. But it's not the case.

Is there a way in SQL where I could get each 'different' part no in the 'sales' table?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.