Page 1 of 1

[SOLVED]Saving data as XML for Export

Posted: Tue May 25, 2004 1:25 am
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

Posted: Tue May 25, 2004 10:11 am
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.

Posted: Tue May 25, 2004 10:30 am
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 :)

Posted: Tue May 25, 2004 12:46 pm
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]