[e-lang] XML library design: what is XPath self? Or, is this "fragment" idea a good one?
bryan rasmussen
rasmussen.bryan at gmail.com
Wed Feb 17 01:11:45 PST 2010
Well the first question is - should this handle malformed XML data - because
> ? xml`<a>xxx</a> yyy <b>zzz</b>`[xpath`a/text()`]
> # value: [xml`xxx`]
is malformed - the XML you give there doesn't have a document node.
> So, for XPath semantics, the above sample implies that the “a” element
> is a child of the context node.
yes it does, but you don't have a context node? if you had
<data><a>xxx</a>yyy<b>zzz</b></data>
and the context node was 'data' the xpath you gave would be correct.
> 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"`]
Yes if the context node is a then the xpath @b should return the value
of the b attribute.
> But this is inconsistent with the previous example, because the XPath
> context node must be the “a” element for this to work! Given this
> model, this must be instead written as:
>
> ? xml`<a b="c">xxx</a>`[xpath`a/@@b`]
> # value: [xmlattr`b="c"`]
>
> or
>
> ? xml`<a b="c">xxx</a>`[xpath`*/@@b`]
> # value: [xmlattr`b="c"`]
>
yes..
> I think this is reasonably the Right Thing given my original premise,
> but I'm wondering whether I should reconsider my original premise.
> What do you think?
The problem with the premise is it is incomplete - do you want to only
handle well-formed XML, then the rest of the premise is wrong, if you
want to handle malformed data then you still need to have a rule as
how the context node is set. For example you could say that malformed
XML has an implicit document node it has already been matched. Which
would match your first example.
Cheers,
Bryan Rasmussen
More information about the e-lang
mailing list