0

im trying to upload a xml data feed to mysql so i can use the database with my php program. The problem that im having is usually i create the fields and import the feed. But the feed i have now is a bit strange..

<name>test</name>
<address>test address</address>
<phone>251447</phone>
</phone_count>
<pets>cat</pets>
</pet_count>
<images>
  <image>1.jpg</image>
  <image>2.jpg</image>
  <image>4.jpg</image>
  <image>16.jpg</image>
</images>

can someone tell me how can i create the fields for </phone_count> </pet_count> because those fields have only the closing tag.

how do i create a field for each image? because i haven't inserted data in a sub set.

im trying to load the data using

LOAD DATA LOCAL INFILE '/tmp/xml/data.xml'
INTO TABLE person_data
1
  • 2
    In XML, only </phone_count> or </pet_count> can not be a valid xml tag Commented Mar 19, 2013 at 14:42

1 Answer 1

1

Your input XML file is broken, there is no such thing as a closing tag without a corresponding opening tag. The author of this XML flow probably meant <phone_count/> and <pet_count/> (notice the position of the forward-slash). This syntax is identical to (e.g.) <pet_count></pet_count>.

Regaring the method for importing this flow, you will not be able to do it with LOAD DATA INFILE because there is a 1-n (one-to-many) relationship between your main entity (I'm guessing something like "Contact") and Images. Ideally, there will be two tables in your database, such as contact and image, and LOAD DATA INFILE allows importing into one table at a time.

You would be better off parsing this file programatically in PHP.

On second thought, if there are at most four images for one givent contact, then I could imagine a contact table with four image1, ..., image4 fields, but I would not consider it good practice.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... The problem was with data feed. They hadn't included the correct tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.