Re: XML library design: what is XPath self? Or, is this "fragment" idea a good one?
bryan rasmussen <[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <[email protected]> |
>> >> 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.. The assumption seems to be though that as well as the virtual root node if we had malformed XML then the API would provide a virtual document node as well - that is then wrong, probably the compromise would be an error in the formedness of the XML could allow you to treat it as malformed and then parsing with some specific rules for treating XML-like markup without it being properly XML. Cheers, Bryan Rasmussen