[Zope] XML Parsed for all platforms?

Zanotti Michele Zanotti@az.aziendasanitaria.trentino.it
Wed, 14 Mar 2001 11:42:21 +0100


Ciao,
I see that XMLParsed 0.1 b3 is only for generic Unix-like platform, =
while
0.1 b1 and b2 are for all platforms. Do you know if XMLParsed =
developers
want to abandon Win platform?=20
Thanks, Michele

-----Messaggio originale-----
Da: Martijn Pieters [mailto:mj@digicool.com]
Inviato: mercoled=EC 14 marzo 2001 10.50
A: Jeff Griffith
Cc: zope@zope.org
Oggetto: Re: [Zope] Natural XML Parsing


On Tue, Mar 13, 2001 at 06:46:42PM -0500, Jeff Griffith wrote:
> Hey All,
>=20
> While messing around with XML I became really frustrated at how =
unnatural
it
> seemed to extract data out of documents.  I ended up writing my own =
python
> class to do exactly what felt natural.  The problem is the entire =
time I
> kept telling myself "this code has to already exist somewhere"  I =
just
could
> never find it.
>=20
> So if anyone is interested take a look at how this class works and =
tell me
> if
> 1) this seems useful
> 2) this is already supported by someone else
>=20
> A brief example of how it is used
> --------------
>=20
> < collection >
>   < comic issue=3D"1">
>      < author > Stan Lee < /author >
>   < /comic >
> < /collection >
>=20
> can be accessed as
>=20
> collection.comic.author.TEXT
> collection.comic.ATTR('issue')
> ---------------
> a more complete write-up w/source is available at
> http://www.people.hbs.edu/jgriffith/simplexmlobject.html

Have you looked at ParsedXML?

  http://www.zope.org/Wikis/DevSite/Projects/ParsedXML/Releases

It is a fully DOM level 2 compliant XML object. It'll let you access =
your
XML via DOM calls. They may seem less convenient than your example, but
will cover the cases where you have more than one 'comic' element.

Your example could translate to:

  xmlDoc.documentElement.childNodes[0].childNodes[0].childNodes[0]
  xmlDoc.documentElement.childNodes[0].getAttribute('issue')

or by using the tagname the first example would become:

  comic =3D xmlDoc.documentElement.getElementsByTagName('comic')[0]
  authorName =3D =
comic.getElementsByTagName('author')[0].getChildNodes(0)

In future versions, XML id support is planned; if you have a DTD that
tells the parser what attributes are Id's, you can traverse the
tree using Id attributes for the same effect. Then you can use a =
document
like:

  <collection>
    <comic issue=3D"1" id=3D"first_issue">
       <author>Stan Lee</author>
    </comic>
  </collection>

and code like:

  comic =3D xmlDoc.getElementById('first_issue')
  authorName =3D =
comic.getElementsByTagName('author')[0].getChildNodes(0)

Hope this helps!

--=20
Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------

_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -=20
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )