[e-lang] XML library design: what is XPath self? Or, is this "fragment" idea a good one?

Thomas Leonard tal at it-innovation.soton.ac.uk
Wed Feb 17 02:36:33 PST 2010


On Wed, 2010-02-17 at 11:20 +0100, bryan rasmussen wrote:
> >>
> >> But what about xml`<a b="c">xxx</a>`?
> >>
> >> Given that one *has* an object which is a single element, one would
> >> imagine it to be natural to want to refer to its attributes directly:
> >>
> >> ? xml`<a b="c">xxx</a>`[xpath`@@b`]
> >> # value: [xmlattr`b="c"`]
> >
> > I'd be happy having the context be the document (or document fragment)
> > containing <a>, rather than <a> itself.
> >
> > Even if xml`<foo/><bar/>` isn't a well-formed document,
> > xml`<foo/><!--comment-->` is, and you still need to be able to refer to
> > the comment.
> 
> Yeah.
> 
> The XPath / is to the root node, a sort of virtual node around the
> document node.
> In the example
> >> ? xml`<a b="c">xxx</a>`[xpath`@@b`]
> >> # value: [xmlattr`b="c"`]
> >
> a would be the document element
> 
> in the example
> ? xml`<a>xxx</a> yyy <b>zzz</b>`[xpath`a/text()`]
> > # value: [xml`xxx`]
> there isn't a document element...
> most APIs have some method for dealing with fragments like the above,
> but understood that they are coming from some well-formed XML that
> does have a document element, thus if you had
> 
> <data><a>xxx</a>yyy<b>zzz</b></data>
> and selected /*
> then your context would be data
> and your fragment would be <a>xxx</a>yyy<b>zzz</b>
> so then the a/text() would work..

I think that would be confusing. In XSLT, you'd select <a> using
"/data/a" even if <data> was the document element.

[ The XML/DOM terminology is rather confusing. The Document corresponds
to the XML file itself, and contains a sequence of Nodes, exactly one of
which must be an Element (i.e. the "document element", a child of the
Document). ]


-- 
Dr Thomas Leonard
IT Innovation Centre
2 Venture Road
Southampton
Hampshire SO16 7NP

Tel: +44 0 23 8076 0834
Fax: +44 0 23 8076 0833
mailto:tal at it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk 



More information about the e-lang mailing list