[XML-SIG] xmlpickle.py ?!

Uche Ogbuji uogbuji@fourthought.com
Wed, 9 Aug 2000 23:14:26 -0600 (MDT)


On Wed, 9 Aug 2000, 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) ?

I see what you're saying.  XPath is no help here because it's not meant to
be.  It's just a very general tree-query tool independent of higher-order
optimizations.

Now if you were using XSLT, which does have the "responsibility" of
providing tools to make tree transformation proper, you have some
help.  XSLT provides two "indexing" methodologies on top of
XPath: id() and key().  With XSLT you can very easily instruct the
processor to index on your example:

<xsl:key name='mykey' match='/dictionary/item' use='key'/>

and later

<xsl:value-of select='key("mykey", "Mike")'/>

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

See above.

> 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.

No problem with XSLT's key().  See the above example.  The node indexed is
really the item node, indexed against the string value of its key child.

--Uche