[XML-SIG] xmlpickle.py ?!
Wed, 09 Aug 2000 10:06:20 +0200
Mike Olson wrote:
> "M.-A. Lemburg" wrote:
> > Mike Olson wrote:
> > >
> > >
> > > No matter how you do it, XPath won't look like python. The "." is not
> > > valid in XPath. Attributes are accessed as with the attribute:: axis
> > > (or @). Ex.
> > >
> > > <Employees Department="Development"/>
> > > <Employee name="Mike">
> > > <Adress>1234 S West Way</Address>
> > > </Employee>
> > > </Employees>
> > >
> > > To get Mike
> > > /Employees/Employee[@name="Mike"]
> > > To get Mikes Address with employee mike as the context:
> > > Address
> > Hmm, looks like it would be more useful to map object names
> > to element names in this case... it doesn't really make sense
> > to access information on a type basis, e.g.
> > /dictionary/item[@key="Mike"]. But then, structure is given by
> > type, not object name. Oh well :-/
> I agree
> > 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>
> > It seems that these XPath lookups have to be context senstive...
> Not always. You can have relative or absolute paths. You can also have
> paths that don't care about position. Here are three examples.
> #1 Assume you have an unknown context with the exact document use:
> #2 Assume you have a context, lets say at item
> #3 Assume there are many dictionary objects in your document, all
> scattered at different levels and you want to get all of the keys names
The last one looks like a great way to search an XML file. I suppose
you can then use the looked up tag as context, right ? In that
case finding the item containing "Mike" as key wouldn't be hard.
Yah, I really should go and read the specs...
Python Pages: http://www.lemburg.com/python/