Load xml into mysql table with element

安稳与你 提交于 2019-12-02 07:42:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!