Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
<?xml version="1.0"?>

<resultset statement="SELECT * FROM test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
    <field name="item">2424</field>
    <field name="header">blah blah 1</field>
    <field name="text" xsi:nil="true" />
    ...
    </row>

  <row>
    <field name="item">5321</field>
    <field name="header">blah blah 2</field>
    <field name="text">some text</field>
    ...
  </row>
</resultset>

My export to xml from mysql looks like above and contains much more fields than needed for the import.

My problem is how to loop through the rows with simplexml in php and only select only some specific fields/names and preserve the datatype (string, null etc.) and format a mysql query ie.:

INSERT INTO table (item, header, text) VALUES ('2424', 'blah blah 1', NULL);

INSERT INTO table (item, header, text) VALUES ('5321', 'blah blah 2', 'some text');
share|improve this question
    
why dont you use LOAD DATA INFILE? –  Gordon Feb 12 '12 at 12:39
    
possible duplicate of Import CSV or XML to MySQL –  Gordon Feb 12 '12 at 12:40
    
possible duplicate of stackoverflow.com/search?q=import+xml+mysql+php –  Gordon Feb 12 '12 at 12:41
    
Because I have much more fields than needed in the received xml export and currenly not sure if the row should be inserted or updated. –  user1070125 Feb 12 '12 at 12:42
    
What do you mean by "more fields" than you need. If you mean that the schema from the xml-source contains additional columns, which you don't need, you can just delete them after the import with ALTER TABLE. If you mean that you don't need rows based on a criteria, you should be more specific as to what the criteria is. –  mahok Feb 12 '12 at 12:47
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.