Should I save my XML feed in a database or use an XML parser to handle it?
I am creating a price comparison script that will work with XML feeds, given to me by many shops. Those XMLs will have the same structure as below
<product id="449135">
<name>MadBiker 600</name>
<link>MadBiker-600.html</link>
<price_with_vat>107.01</price_with_vat>
<category id="148807">For men</category>
<imag开发者_开发百科e width="280" height="280">p1.1.jpg</image>
<description>desc goes here</description>
</product>
To handle it I have two options. Proceeding with an XML flat-file or save those data/values in a database. I have read that there are some low memory parsers like SAX/XMLReader.
What interests me more is to use a parser to a single file, instead of using a RDBMS.
What is your opinion on this?
Thank you
It depends mostly on the use you want to put the data to.
I'm assuming that you will want to be able to sort and filter the data (e.g. "sort by price, desc", or "filter by category=mens"). I'm also assuming you need some kind of "relevance" calculation and search feature.
I'm also assuming that you will be constantly adding, removing and changing comparison data.
Broadly speaking, those things are easier to do in SQL than by parsing an XML file - especially at scale.
On the other hand, SQL makes it hard to represent different data attributes for different types of product (bicycles might need frame size, clothes might need colours). If this is part of your problem, XML makes the data storage easier - you define a schema/dtd and write documents that adhere to the schema.
精彩评论