[SOLVED]Saving data as XML for Export

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

[SOLVED]Saving data as XML for Export

Post by bluenote »

Hi all,

i hope i post this in the right forum ;-) so here's my question: i have to export a whole MySQL database with 9 relational connected tables and a total of about 22.000 rows to an PostgreSQL db - this does not sound like a big Prob, but 'the other side' does not want .sql, .txt, .csv or simple .xml files - they want the export files matching THEIR xml scheme.

So does anyone of you have experiences with pulling data from MySQL via PHP into an XML scheme?

Code: Select all

- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
- <xs:simpleType name="accessType">
- <xs:restriction base="xs:string">
  <xs:enumeration value="intern" /> 
  <xs:enumeration value="public" /> 
  <xs:enumeration value="user" /> 
  </xs:restriction>
  </xs:simpleType>
I have a field in one of the nine db's which has the name 'accessType' and it can have the values shown above.

This is not a 'Hey Guys do my work and write my code' post - i just need an initial idea to do this.

Greez and TiA,
- bluenote
Last edited by bluenote on Sun Aug 08, 2004 1:09 am, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Write an xml template file - 'the other side' can probably supply one, or at least a file with static content.

Replace all the static content with embedded echo calls.

Write a script which defines the dynamic content, then include the template (with embedded echo's) in the same scope as the vars.

Wrapping the include call with output buffering will allow you to write the output to file rather than immediately printing to browser.

If you have rows of data to print it's basically the same deal except that now you need a custom function/class to print rows rather than a simple echo. A decorated iterator is maybe the best way to do this. Or you can define an array of (unformatted) row data, then loop through this with a simple foreach fn, printing each row with added xml tags.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

bluenote - If you're using MySQL 4.x it can export the database into an XML format (mysql -xml -e "query"). However I suspect you already know this. You could then parse this XML file into a new format required for Postgres.

Alternatively echo out all of the XML yourself I guess :)
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

:lol: Thanx Mc Gruff - that was the idea i needed ...
Write an xml template file - 'the other side' can probably supply one, or at least a file with static content.

Replace all the static content with embedded echo calls.
'The other side' does provide an XML template. When i am through with the coding, i can post it here for other fellows with the same problem.

You Guyz rule!

Thanx,
- bluenote[/quote]
Post Reply