简体   繁体   中英

shell script to load xml file into mysql database

I have an xml file as:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<table name="abc">
<row>
<field name="year">2015</field>
<field name="copyright">Various</field>
<field name="review">Various</field>
</row>
<field name="year">2015</field>
<field name="copyright">Various</field>
<field name="review">Various</field>
<row>
<field name="year">2015</field>
<field name="copyright"/>
<field name="review"/>
</row>
</table>

The command for loading this xml file into mysql database is :

LOAD XML LOCAL INFILE '/home/first.xml' INTO TABLE abc;

But this command is showing fields in database having proper closing tags. In the third row copyright and review are having closing tags as /> So its showing entire row values as NULL even if year is having value as 2015 . How this issue can be resolved any ideas??

I will give you two documents. You should use both.

  1. Using mysql in bash script
  2. Load xml into MySQL

First connect to mysql from bash script and then run load xml command in that batch.

Using Java i replaced /> with ></field> . So now the values are properly getting entered in db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM