PHP Classes

Value Dump

Recommend this page to a friend!

      Generic XML parser class  >  All threads  >  Value Dump  >  (Un) Subscribe thread alerts  
Subject:Value Dump
Summary:Obtaining useful values
Author:Jon Slack
Date:2008-07-01 14:43:21
Update:2008-07-02 16:01:35


  1. Value Dump   Reply   Report abuse  
Jon Slack - 2008-07-01 14:43:21
It would appear that what most prople want when looking for an XML Parser, is to obtain the values held in an XML file, rather than the structure. After all, you can see the structure by opening in a browser.

Would it be possible to provide a function to output the actual values from an XML file in a way that print_r() can provide something meaningful?

I suspect that most people would want to parse an XML file in order to put the values in arrays in order to do something useful with them, or MySQL data files for more accessible storage.

Whilst I agree that a competent programmer should be able to take the output from this class and do just that, not everyone who uses this site is as experienced.

  2. Re: Value Dump   Reply   Report abuse  
Jon Slack - 2008-07-01 14:51:44 - In reply to message 1 from Jon Slack
foreach($parser->structure as $struct)
echo "<br />";

Sorted! :)

  3. Re: Value Dump   Reply   Report abuse  
Manuel Lemos - 2008-07-01 20:54:42 - In reply to message 2 from Jon Slack
Sounds like a good idea but I am not sure what to do in certain cases.

For instance, a a tag with the same name may be repeated in the array structure. How do you expect that to be returned?


Also, a tag value may mix data and other tags. How do you expect that to be returned?

data <tag>value</tag> more data

  4. Re: Value Dump   Reply   Report abuse  
Jon Slack - 2008-07-02 16:01:35 - In reply to message 3 from Manuel Lemos
You're absolutely right - I had exactly that problem. I had an XML file that had several nested sets of data and the nested arrays had the same name as the arrays themselves. Nightmare. It's a pity this is 'allowed' in XML - a major failing really.

In order to combat that, I actually dumped the program that generated the XML file in favour of one that used more sensible array-naming conventions. The problem actually came to light when using another XML Parser from this site - it choked when it found an apparent end tag in the 'wrong' place.

There's a project here for someone with more time than I have at present :o)