[XML-SIG] xmlpickle.py ?!

Mike Olson Mike.Olson@fourthought.com
Wed, 09 Aug 2000 11:35:18 -0600

"M.-A. Lemburg" wrote:
> uche.ogbuji@fourthought.com wrote:
> >
> > > BTW, how would one access "Mike" in this XML file without reverting to
> > > positional indexing ?
> > >
> > > <dictionary>
> > >       <item>
> > >               <key>Mike</key>
> > >               <value><address>1234 Main Street</address></value>
> > >       </item>
> > > </dictionary>
> >
> > Hmm?  No positional indexing neede, I'd think:
> >
> > xml.xpath.Evaluate('string(/dictionary/item/key)')
> >
> > would return "Mike".
> >
> > Maybe I misunderstand you.
> What happens if your dictionary has 100 entries and you
> want to lookup "Mike" (which is stored as content of key) ?

> And once you've found it, how would you get at the corresponding
> value ?

This will work

string(/dictionary/item[key = 'Mike']/value)

> Sorry for my ignorance shining through here. I should
> really read the XPath specs... ALAS, no time for this now.
> > > It seems that these XPath lookups have to be context senstive...
> >
> > They do, but how does that imply "positional indexing"?
> Well, I guess sometimes you'd have to look ahead (in terms of
> structure depth) to find the right tag and then back out
> again to read the container as a whole, e.g. in the above
> case the item.

Quick XPath tutorial.....

An XPath expression is made up of a series of steps.  Each step contains
an axis, node test, and a set of predicates.  the axis defines a set of
nodes based on the context, ie child::, attributes::, ancestors::.  the
node test is then applied to each in this set, ie node(), text(), item. 
Each item in the original set that meets the node test is then filtered
by each predicate, ie [position() = 1], [key = 'Mike'].  The nodes from
the axis set that meet all of these filters are then used as context
nodes for the next step (or are the results if this is the last step).

There a many abbreviations  The step "dictionary" is an abbreviated
syntax for child::dctionary.

So, you can perform any tests at any step then move on.

To break down :
string(/dictionary/item[key = 'Mike']/value)
In more detail
1.  All children of the root that have the tag name dictionary are the
results of the first step.
2.  All children of all results from step 1 that have the tag name item
_and_ have a child called key with a string value of Mike are the
results of the second step.
3.  All children of all results from step 2 that have a tag name of

The spec obviously explains this is much better detail, but I hope this


> Thanks,
> --
> Marc-Andre Lemburg
> ______________________________________________________________________
> Business:                                      http://www.lemburg.com/
> Python Pages:                           http://www.lemburg.com/python/

Mike Olson				 Principal Consultant
mike.olson@fourthought.com               (303)583-9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
Software-engineering, knowledge-management, XML, CORBA, Linux, Python