Re: easy and simple way to read xml into array
| From: | Lucian Cozma | Date: | Wed, 19 Nov 2003 12:46:04 +0000 |
| Subject: | Re: easy and simple way to read xml into array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-170263@lists.php.net to get a copy of this message | ||
The 'sample.xml' file:
<?xml version="1.0"?>
<root>
<ingrediens no="1">
<ingrediensnummer>1234</ingrediensnummer>
<maengde>3,4</maengde>
<enhed>kg</enhed>
</ingrediens>
<ingrediens no="2">
<ingrediensnummer x="2">12345</ingrediensnummer>
<maengde>3,1</maengde>
<enhed>t</enhed>
</ingrediens>
</root>
"Victor spång arthursson" <scooterbabe@home.se> wrote in message
news:20C141A0-19C0-11D8-9101-00039344A3C4@home.se...
2003-11-17 kl. 17.06 skrev Chris Hayes:
>> Need to read a xml-file into an array, but searching around I havent
>> found a way that's easy and simple
Arent there an easy way in PHP to
>> accomplish this?
>
> have you been at http://se.php.net/xml ?
Well, I've, and I also have to say that the XML-support in PHP lacks
any usability
2 pages code later I still cannot get it to work, and the manual is
pretty thin on this chapter...
For example, I've the following XML:
<ingrediens>
<ingrediensnummer>1234</ingrediensnummer>
<maengde>3,4</maengde>
<enhed>kg</enhed>
</ingrediens>
Here I thought that the startelementfunction should be called upon
every start tag, the character_data_handler on every text string and
the endelement function on every endelement.
But what seems to happen is that the character data handler is called
to randomly number of times, and if I output the current element every
time it gets called I get the following output for the xml above:
ingrediens
ingrediens
ingrediens
ingrediensnummer
ingrediensnummer
ingrediensnummer
ingrediensnummer
maengde
maengde
maengde
maengde
enhed
enhed
enhed
enhed
enhed
enhed
What I expected to get was:
ingrediensnummer
maengde
enhed
So, couldnt anyone please bring some clarity into this matter?
Sincerely
Victor=