-1

I need to save data from a relational database record set in MySQL (composed of multiple tables and multiple sub-records for each master record) to an xml file. My questions are:

  1. Is there an xml standard format for defining the relation between the database structure and the xml to output?
  2. Are there recommended open-source libraries in PHP that would do the job?
Yirmiyahu Fischer
  • 503
  • 2
  • 9
  • 22
  • 1
    possible duplicate of [How to convert a MySQL DB to XML?](http://stackoverflow.com/questions/1420205/how-to-convert-a-mysql-db-to-xml) – Dipen Shah Jun 30 '15 at 14:49
  • not the same question -- I need to export specific data into a more specific format -- not exporting the entire db, as the linked question states. Additionally, my question asks if there is a meta-xml format to define the relation between the data from the db and the output xml format. – Yirmiyahu Fischer Jun 30 '15 at 15:20
  • http://stackoverflow.com/questions/5112282/get-mysql-database-output-via-php-to-xml does this help? – Dipen Shah Jun 30 '15 at 15:22
  • Better, but the question/answers are still a matter of hard-coding the conversion of the sql data to the xml format. My goal is to get an xml standard of flexibly doing this. – Yirmiyahu Fischer Jun 30 '15 at 15:36
  • could you edit the question and be more specific. Maybe give some sample input and output? – Dipen Shah Jun 30 '15 at 15:40
  • http://www.w3.org/XML/RDB.html and with *id* and *ref* you can model of relations in XML: http://www.w3.org/XML/Datamodel.html – hakre Jun 30 '15 at 18:51

1 Answers1

1

It is possible to export and import XML data using the mysql monitor.

$ mysql -uroot -p --xml -e 'SELECT * FROM tablename' > /tmp/tabllename.xml

The mysql monitor has an --xml option, which enables us to dump data in XML format. The -e option executes a statement and quits the monitor.

For whole database you can use mysqldump tool

mysqldump --xml databasename > databasename.xml  
  or 

mysqldump -X databasename> databasename.xml

Hope it helps!!

kehsihba
  • 11
  • 1
  • Thanx, but I need something a bit more flexible. I have a specific format of xml, and the record set I am dealing with consists of multiple tables. Something like:
    
        
         value1
         value2
         ...
         
          value_x
          value_y
         
         
          value_x
          value_y
         
        
    
    – Yirmiyahu Fischer Jun 30 '15 at 15:14