Advertisement

08.31.2007 at 03:46AM PDT, ID: 22799583
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.1

Parsing large XML files into mySQL using PHP

Asked by Kobz46 in MySQL Server, Extensible Markup Language (XML), PHP and Databases

Tags: , , , ,

I have XML files ranging from 10Kb to 1.5Gb. They contain product information. (see sample XML file below.) I need to write the product information into a mySQL table using PHP without reading the whole XML file into an object and using a whole lot of system memory. I've researched this a bit and found that XMLReader might be the best way to go as it cursors through the XML eliminating the need to read the whole file into an object.

As you can see from the sample below, some of these product detail tags might be empty. A sample SQL statement would look something like this: INSERT INTO tblprod (SKU,NAME,DESC,LDESC,URL,CAT,CATID,PRICE,STOCK,KEYW,BRAND) VALUES ($SKU,$NAME,$DESC,$LDESC,$URL,$CAT,$CATID,$PRICE,$STOCK,$KEYW,$BRAND) WHERE StoreGUID = $StoreGUID

How do I go about writing each individual product's data into mySQL? Can anyone please help with some code and explain the process to me? This needs to happen as fast as possible, and without using excessive system memory.

SAMPLE XML: (shows the information for 2 products)

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <ROOT>
  <StoreGUID>068e2904-6f91-4364-bd4e-c9351567facb</StoreGUID>
- <PRODUCT>
  <ACTION>ADD</ACTION>
  <SKU>NKFI01</SKU>
  <NAME>OPTICAL MOUSE</NAME>
  <DESC>This is a SHORT description.</DESC>
  <LDESC>This is a LONG description.</LDESC>
  <URL>http://www.mymouse.com?productid=16273</URL>
  <CAT>COMPUTERS|INPUT</CAT>
  <CATID>364</CATID>
  <PRICE>205</PRICE>
  <STOCK>10</STOCK>
  <KEYW>MOUSE|OPTICAL|COMPUTER</KEYW>
- <Attrib>
    <BRAND>LOGITECH</BRAND>
  </Attrib>
  </PRODUCT>

- <PRODUCT>
  <ACTION>ADD</ACTION>
  <SKU>NKFI02</SKU>
  <NAME>OPTICAL MOUSE2</NAME>
  <DESC>This is a SHORT description2.</DESC>
  <LDESC>This is a LONG description2.</LDESC>
  <URL>http://www.mymouse.com?productid=16274</URL>
  <CAT>COMPUTERS|INPUT</CAT>
  <CATID />
  <PRICE>210</PRICE>
  <STOCK>5</STOCK>
  <KEYW />
- <Attrib />
  </PRODUCT>Start Free Trial
[+][-]08.31.2007 at 11:28AM PDT, ID: 19810343

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL Server, Extensible Markup Language (XML), PHP and Databases
Tags: xml, php, large, mysql, file
Sign Up Now!
Solution Provided By: fibo
Participating Experts: 2
Solution Grade: C
 
 
[+][-]02.01.2008 at 02:40AM PST, ID: 20795514

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_1_20070628