【问题标题】:How to import xml files with mysql LOAD XML LOCAL INFILE如何使用 mysql LOAD XML LOCAL INFILE 导入 xml 文件
【发布时间】:2017-08-12 15:09:49
【问题描述】:

我需要帮助将 xml 文件导入表,xml 文件有数百万条记录。

首先我使用的是simplexml_load_file,然后放一个循环来逐个插入记录,这需要很多时间。我已经使用了 csv 的 infile 并且效果很好,任何人都可以帮忙,我怎样才能对 xml 做同样的事情。

我正在尝试

LOAD XML LOCAL INFILE "C:/xampp/htdocs/class/on_the_list.xml" INTO TABLE tbl_juju ROWS IDENTIFIED BY '<job>' 

运行此查询会显示“MySQL 返回了一个空结果集(即零行)” 并且没有插入任何记录。下面是xml格式。

<?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0" xmlns:on-the-list="http://www.on-the-list.com/rss/2.0">
    <positionfeed>
    <on-the-list:import user="accounts@juju.com" site="www.juju.com" />
    <job>
    <id>335951659</id>
    <employer>The Judge Group</employer>
    <title>Java Developer</title>
    <description>Our client is currently seeking a Java Developer No C2C or 1099 Responsible for designing, developing, modifying, and evaluating programs for internal functional areas including finance, human resources, and marketing. Analyzes existing programs or formulates logic for new systems, devises logic procedures, prepares flowcharting, performs coding, and tests/debugs programs. Develops conversion and system implementation plans. Prepares and obtains approval of system and programming documentation. Recommends changes in development, maintenance, and system standards. Trains users in conversion and implementation of system. Education: 4-year degree in computer science or related field or equivalent experience Experience: 2+ years of experience in programming on enterprise or department servers or systems</description>
    <postingdate>2017-02-25</postingdate>
    <joburl>http://www.juju.com/jad/000000005k0lyj?partnerid=6facb3068fcc5ef5aa89a8cfe85e2aba&amp;exported=True&amp;hosted_timestamp=0042a345f27ac5dc911e5aa0246d6d5bb48607f376ce73ce76134eafb3ea2826</joburl>
    <location>Jacksonville, FL</location>
    <category>Software/IT</category>
    <zip />
    </job>
    <job>
    <id>335951624</id>
    <employer>Driveline Retail</employer>
    <title>Retail Merchandiser</title>
    <description>Drivelineis currently seeking motivated and career-minded candidates to join itsnational network of retail merchandisers. Weowe our continued success to the hard working, intelligent and innovativepeople who implement our retail programs every day. If you're interested injoining the team and helping our clients drive sales, then we'd love to hearfrom you. AboutDriveline: . Driveline is thelargest non-broker merchandising services agency in the country . Our clientsinclude major national retailers and manufacturers . Ourindustry-leading software makes your job easier and makes it easier than everto manage your own schedule and report hours . We offer full W-2employment, meaning no surprise tax bills from 1099 forms . We offercompetitive wages and opportunities for advancement (reimbursement is alsoavailable for travel more than 60 miles in one day) Desired experience/skills: . 1-2 yearsmerchandising or retail experience . Outstandingcustomer service skills . Ability to workboth independently and as part of a team . Ability to readstandard plan-o-grams and execute merchandise resets . Ability to liftup to 30 pounds and bend/stoop/stand for more than 45 minutes Requirements: . Reliabletransportation . Ability tomaintain a professional appearance . Computer access withprinter/Internet/email . Ability to reportcompleted work on the day of service Want to learn more or apply now? Go to www.drivelineretail.com , click on the"Apply Now" button in the top, right-hand corner of the page and complete anapplication. Our recruiters will handle the rest! We look forward to meeting you. -OR- APPLY NOW BY CLICKING BELOW ?territory_id_no=0 Desired experience/skills: . 1-2 years merchandising or retail experience . Outstanding customer service skills . Ability to work both independently and as part of a team . Ability to read standard plan-o-grams and execute merchandise resets . Ability to lift up to 30 pounds and bend/stoop/stand for more than 45 minutes</description>
    <postingdate>2017-02-24</postingdate>
    <joburl>http://www.juju.com/jad/000000005k0lxk?partnerid=6facb3068fcc5ef5aa89a8cfe85e2aba&amp;exported=True&amp;hosted_timestamp=0042a345f27ac5dc911e5aa0246d6d5bb48607f376ce73ce76134eafb3ea2826</joburl>
    <location>St. Petersburg, FL</location>
    <category>Retail</category>
    <zip />
    </job>
    </positionfeed>
    </rss>

等待您的帮助。 提前致谢。

【问题讨论】:

    标签: php mysql xml mysqli load-data-infile


    【解决方案1】:

    试试这个

    LOAD DATA LOCAL INFILE 
        '".$path."'
        INTO TABLE 
        tbl_juju
        CHARACTER SET 'utf8'
        LINES STARTING BY '<job>' TERMINATED BY '</job>'
        (@tmp)
        SET
        id      = ExtractValue(@tmp, '//id'),
        employer = ExtractValue(@tmp, '//employer'),
        title = ExtractValue(@tmp, '//title'),
        description = ExtractValue(@tmp, '//description'),
        postingdate = ExtractValue(@tmp, '//postingdate'),
        joburl = ExtractValue(@tmp, '//joburl'),
        location_city = ExtractValue(@tmp, '//location_city'),
        location_state = ExtractValue(@tmp, '//location_state'),
        category = ExtractValue(@tmp, '//category'),
        vin = ExtractValue(@tmp, '//vin'),
        location = ExtractValue(@tmp, '//location')
    

    【讨论】:

    • 非常感谢,它正在按预期工作:)。
    猜你喜欢
    • 2020-08-31
    • 2013-10-23
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2013-01-14
    • 2014-11-28
    相关资源
    最近更新 更多