1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Import XML files into MySQL

Discussion in 'MySQL' started by giorgioarmani, Mar 28, 2018.

  1. #1
    I am interested in importing various XML files into a MySQL database.
    SEMrush
    Anyone here have experience with this?
     
    giorgioarmani, Mar 28, 2018 IP
    SEMrush
  2. jestep

    jestep Prominent Member Premium Member

    Messages:
    3,640
    Likes Received:
    212
    Best Answers:
    18
    Trophy Points:
    330
    #2
    jestep, Mar 28, 2018 IP
  3. JEET

    JEET Well-Known Member

    Messages:
    2,179
    Likes Received:
    100
    Best Answers:
    1
    Trophy Points:
    185
    #3
    The simplest way is to parse the XML and build a query.
    But this works only if the file is fairly small in size,
    else either the script will keep timing out,
    or you won't have enough memory to load the entire XML file in a variable for parsing,
    or you'll keep losing connection to mysql.

    If the file is very large,
    use a php script to cut it into smaller chunks,
    then run the query script on individual files...

    You can cut it in chunks by reading file line by line,
    and writing 100-200-500 items in a new file,
    ultimately ending up with ,3,4 etc smaller files.

    This will be very difficult if XML file is like this:
    <item><title>some title</title><description /></item><item><title>some title</title><description /></item><item><title>some title</title><description /></item><item><title>some title</title><description /></item><item><title>some title</title><description /></item>

    But very easy if its like this:
    <item>
    <title>some title</title>
    <description />
    </item>
    <item>
    <title>some title</title>
    <description />
    </item>
     
    JEET, Mar 30, 2018 IP