Re: Parse Problem

From: Date: Wed, 10 May 2006 18:30:49 +0000
Subject: Re: Parse Problem
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-41840@lists.php.net to get a copy of this message
Andy Rolls-Drew escribió:
All, I am fairly new to parsing XML using PHP and wonder if anyone has a solution to the following. I have a file eg:- <<?xml version="1.0" ?> <STOREITEMS> <CREATED value="Wed Mar 15 8:07:27 GMT 2006"> <CATEGORY id='67' name='Herbal Pharmacy'> <PRODUCT ITEM='603'> <NAME></NAME> <MODEL></MODEL> <PRICE></PRICE> <PRODUCT ITEM='608'> <NAME></NAME> <MODEL></MODEL> <PRICE></PRICE> <CATEGORY id='69' name='Extras'> <PRODUCT ITEM='1123'> <NAME></NAME> <MODEL></MODEL> <PRICE></PRICE> <PRODUCT ITEM='2034'> <NAME></NAME> <MODEL></MODEL> <PRICE></PRICE> And so on. I have managed to parse a little of it using Magic Parser but I still cant manage to split the products and categories correctly. If there weren't multiple products for each category I think I would have it. Any help would be a start. Thanks in advance Andy ARD Drive Consultants Drive to Perfection Rolls-Drew, Andrew Director ARD Drive Consultants Ltd 169 Nottingham Road Melton Mowbray Leicestershire UK <mailto:andyrd@ard-drive.co.uk> andyrd@ard-drive.co.uk AIM: DarkoneARDDrive tel: fax: mobile: Skype ID: +44 7092 162782 +44 7092 162782 +447929418215 andyrd <https://www.plaxo.com/add_me?u=30065438052&v0=1330159&k0=-1748648187> Add me to your address book... <http://www.plaxo.com/signature> Want a signature like this? Hi,
That is only a piece of your XML data? or mayve did you wrote it by hand to send us the email? If that's a piece of the real data you use, bad!! you wouldn't be able to use any XML parser as it isn't valid XML data. All tags must be closed before opening again the same tag name -unless it does belong to the previous tag (but I don't bet for this in your case)-. Your data should look similar to this: (notice the *missing* closure tags. ah! I added the dots for indentation purposes, it is not valid in XML!). Where did you got this XML file? or perhaps is it created by yourself? <CATEGORY id='67' name='Herbal Pharmacy'> ..<PRODUCT ITEM='603'> ....<NAME></NAME> ....<MODEL></MODEL> ....<PRICE></PRICE> ..<PRODUCT ITEM='608'> ....<NAME></NAME> ....<MODEL></MODEL> ....<PRICE></PRICE> ..*</PRODUCT>* ->> *missing*! *</CATEGORY>* ->> *missing*! <CATEGORY id='69' name='Extras'> ..<PRODUCT ITEM='1123'> ....<NAME></NAME> ....<MODEL></MODEL> Anyway, you could have a look to this thread on php-general, about an example I've sent some days ago, as simple XML parsing for dynamic structures. Give a look to the xml file structure, that is a correct XML file, and the parsing example: http://archive.netbsd.se/?ml=php-general&a=2006-04&m=1973183 Regards, Gonzalo Monzón.

« previous php.db (#41840) next »