[XML-SIG] xmlpickle.py ?!
Mike Olson
Mike.Olson@fourthought.com
Wed, 09 Aug 2000 11:36:37 -0600
"M.-A. Lemburg" wrote:
>
> 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[0]
> > >
> > > 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:
> > /dictionary/item/key[text()='Mike']
> > #2 Assume you have a context, lets say at item
> > key[text()='Mike']
> > #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
> > mike
> > //dictionary/key[text()='Mike]
>
> 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.
Yes, but it is not recommended. Imagine a 100 MB file. the "//" step
will look at every node. Yikes! If you know the path it is recommed
that you use it.
Mike
>
> Yah, I really should go and read the specs...
>
> 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