MySQL Forums
Forum List  »  Connector/Node.js

Import xml with short tags into mysql‏
Posted by: Weibang Tao
Date: August 12, 2012 08:18PM

I need to load some xml files into a mysql database.. I did it using
LOAD XML and it works fine.. but sometimes I have some xml with short
code in it and it did not work...


How to repeat:
load xml local infile 'D:\\file_xml.xml' into table book rows identified
by '<Book>'

and I have a book table with ID, TITLE, PRICE columns..

If the xml is like:
<Books>
<Book>
<ID>1</ID>
<TITLE>Test1</TITLE>
<PRICE></PRICE>
</Book>
<Book>
<ID>2</ID>
<TITLE>Test2</TITLE>
<PRICE>123</PRICE>
</Book>
</Books>

The above table is filled correctly...
ID - TITLE - PRICE
1 - Test1 -
2 - Test2 - 123

Otherwise if I have an xml file like:
<Books>
<Book>
<ID>1</ID>
<TITLE>Test1</TITLE>
<PRICE />
</Book>
<Book>
<ID>2</ID>
<TITLE />
<PRICE>123</PRICE>
</Book>
</Books>

The table is not filled properly and I will have
ID - TITLE - PRICE
1 - Test1 -
2 - 123 -

Options: ReplyQuote


Subject
Written By
Posted
Import xml with short tags into mysql‏
August 12, 2012 08:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.