Re: Re: simple xml api
| From: | Christian Stocker | Date: | Fri, 31 Jan 2003 10:51:56 +0000 |
| Subject: | Re: Re: simple xml api | ||
| References: | 1 2 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-8@lists.php.net to get a copy of this message | ||
On Thu, 2003-01-30 at 22:12, Dirkjan Ochtman wrote:
> I like the ideas around here a lot... I'm don't know too much about C, so
> unfortunately I won't be able to help out to much with coding the new
> extension, but I'd like to provide some feedback and help writing
> documentation (got doc-karma anyway...). One thing is that I'd hope the new
> extension would be called xml as opposite to domxml. Especially if it's
> going to be an extension comprising all the different stuff.
yeah, domxml is not the right name anymore. but ext/xml is taken
already. maybe ext/libxml2 as it's based on this library, but I don't
like it that much, eiter :)
chregu
> I have written PHP scripts that use the sax extension to build a DOM-kind of
> tree that's (at least in my view) really easy to use. It uses some kind of
> nodes and lots of arrays and stuff... If you're interested, I could post
> some code.
>
> Regards,
>
> Dirkjan
>
> "Sterling Hughes" <sterling@bumblebury.com> wrote in message
> news:1043947104.15187.980.camel@hasele...
> > Sam Ruby sent me the following URL:
> >
>
> http://dev2dev.bea.com/articlesnews/discussion/thread.jsp?thread=JSchneider_
> XML
> >
> > It looks really neat, and much in the PHP way of doing things. Take the
> > following XML document, and I'll show you how easy parsing it is with
> > the Simple API proposed above (ported slightly to PHP).
> >
> > Let's say we're a bar, and we have a list in XML of the different beers
> > on tap.
> >
> > <beers>
> > <beer>
> > <name>Becks</name>
> > <nation>Germany</nation>
> > </beer>
> > <beer>
> > <name>Heineken</name>
> > <nation>Netherlands</nation>
> > </beer>
> > <beer>
> > <name>Hefeweißer</name>
> > <nation>Germany</name>
> > </beer>
> > <beer>
> > <name>Samuel Adams</name>
> > <nation>USA</nation>
> > </beer>
> > <beer>
> > <name>Coors</name>
> > <nation>Not surprisingly, no one claims ownership</nation>
> > </beer>
> > <beer>
> > <name>Budweiser</name>
> > <nation>Germany</name>
> > </beer>
> > </beers>
> >
> > <?php
> > // $file contains the xml above
> > $tap = new Simple_XML($file);
> > foreach ($tap->beers as $beer) {
> > var_dump($beer->name);
> > // string "Name of Beer"
> > }
> >
> > $nations = array_unique($tap->range($tap->beers, "nation"));
> > // All the represented nations in the file
> >
> > $germanBeers = $tap->search($tap->beers,
> > create_function('if ($beer->nation == "Germany") return 1; return
> > 0;')
> > );
> >
> > // you can also query using Xpath documents
> >
> > var_dump($tap->beers[0]->name);
> > // string (5) "Becks"
> >
> > // Modifying documents
> > $tap->beers[0]->name = "Killians Red";
> > $tap->beers[0]->nation = "Ireland";
> >
> > // Add a meta data element, and set the various data
> > foreach ($tap->beers as $beer) {
> > $beer->metadata->type = "Heavy";
> > $beer->metadata->audience = "People with chest hair";
> >
> > // $distributors is another XML document that we now
> > // merge with the current document
> > $beer->metadata->distributors = $distributors->list;
> >
> > $tasty = $beer->name == "Coors" ? "No!" : "Yes";
> >
> > $beer->metadata->attributes = <<<ASSIGN_XML
> > <attribute>
> > <tasty>$tasty</tasty>
> > </attribute>
> > <attribute>
> > <filling>yes</filling>
> > </attribute>
> > ASSIGN_XML;
> > }
> > ?>
> >
> > To me, this just seems like the PHP5 way of doing XML. Simple, Elegant
> > and Efficient. We could of course provide DOM and SAX for the purists
> > (SAX is also better for large files), and people using XSLT. However, I
> > think this API just maps itself to the problem domain perfectly (and
> > could easily be implemented on top of libxml).
> >
> > Thoughts?
> >
> > -Sterling
> >
> > PS: Yes, I do know xml_parse_into_struct(). This is different.
> >
> > --
> > "First they ignore you, then they laugh at you,
> > then they fight you, then you win."
> > - Gandhi
> >
--
christian stocker | bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71
http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid
0x5CE1DECB