简体   繁体   中英

How to insert data from xml to mysql using LOAD XML LOCAL INFILE

I am trying to insert data from xml to mysql database using LOAD XML LOCAL INFILE in php but it inserted blank values for self closed xml tags like <Password />
here is the xml code

<?xml version="1.0" encoding="UTF-8" ?>
    <Users>
        <User>
            <Password />
            <Name>name1</Name>
        </User>
    </Users>
php mysql code:
LOAD XML LOCAL FILE 'users.xml' INTO TABLE data users ROWS IDENTIFIED BY '<User>';
how can i insert the name into the database? (this is the sample xml and i have xml with more than 9000 rows).

我得到了答案
$doc = new DOMDocument();
$doc->load($xml_file_name); //load xml file $xml_file_name='xml file name'
$doc->save ( $xml_file_name, LIBXML_NOEMPTYTAG ); // code to remove empty records or self closed tag

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