Re: simple xml api
| From: | Sterling Hughes | Date: | Fri, 31 Jan 2003 13:55:11 +0000 |
| Subject: | Re: simple xml api | ||
| References: | 1 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-10@lists.php.net to get a copy of this message | ||
On Fri, 2003-01-31 at 05:55, Christian Stocker wrote:
> On Thu, 2003-01-30 at 18:18, Sterling Hughes wrote:
> > Sam Ruby sent me the following URL:
> > úèÜ
> > d|ѳ÷Èí®íÆ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).
>
> IMHO, it's a nice way to approach XML documents which are relatively
> shallow like the example below (data centric XML-docs). But I wouldn't
> want to process something Docbook-style with that :) And how does it
> handle attributes, comments, processing instructions, namespaces, etc.?
>
You would want to process something like docbook? :-)
attributes and namespaces are just another level of indirection. ie:
<php.dev>
<php.dev.xml>cool</php.dev.xml>
</php.dev>
var_dump($php->dev->xml);
// string (4) "cool"
and
<simple>
<name length="4">John</name>
</simple>
var_dump($simple->name->length);
// int (4)
var_dump($simple->name);
// string (4) "John"
Or we could make them associative array accesses:
var_dump($simple->name['length']);
// int (4)
Processing instructions could be per node arrays. Remember, since we're
overloading we can do some magic here. Comments could be in a "special"
array $node->__comments.
> So, it would be certainly a nice additon to DOM/SAX/XSLT, but it can't
> provide a replacement for them (again IMHO...)
Agreed. But what I like about is that its a much simplified subset of
95% of what most people want to do.
-Sterling
--
"The computer programmer is a creator of universes for which he
alone is responsible. Universes of virtually unlimited complexity
can be created in the form of computer programs."
- Joseph Weizenbaum