问题
I am trying to load an xml file in a table. The issue is that XML elements are being inserted into the table together with their data.
Here is the table fields:
programname programurl catalogname lastupdated name keywords description sku manufacturer manufacturerid, upc currency price buyurl impressionurl imageurl advertisercategory promotionaltext instock
Here is my code
LOAD DATA LOCAL INFILE '/home/public_html/apw.xml' INTO TABLE
apw ROWS IDENTIFIED BY '<product>' FIELDS TERMINATED BY '\n';
(id,
programname,
programurl,
catalogname,
lastupdated,
name,
keywords,
description,
sku,
manufacturer,
manufacturerid,
upc,
currency,
price,
buyurl,
impressionurl,
imageurl,
advertisercategory,
promotionaltext,
instock);
So for instance, the field programname got inserted with data of "Auto Parts Warehouse" instead of "Auto Parts Warehouse" and programurl "url" instead of "url" What iam i doing wrong>
回答1:
Remove the semicolon after FIELDS TERMINATED ...
You should use the LOAD XML ... Syntax, too. See http://dev.mysql.com/doc/refman/5.5/en/load-xml.html:
The LOAD XML statement reads data from an XML file into a table
Your LOAD DATA INFILE ... is used to load a flat-file (csv) to a table, not a XML:
The LOAD DATA INFILE statement reads rows from a text file into a table
来源:https://stackoverflow.com/questions/27574729/load-xml-into-mysql-table-with-element