OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Concerned about the increasing reliance on XPath

On 09/05/2011 15:33, Stephen D Green wrote:
> An example of the reasons for my exacerbations with XPath
> and my own questions about reliance on it
> I've been trying XPath expressions which would be tests I
> could apply to some XML for validation during processing
> (of a dataset in some ASP.NET, in this case, which seems
> a sensible use case).
> Here is an example fragment
> <a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; version-id="0.4"
>      xmlns="http://example.com";>
> ...
> In XPath 1.0
> /default:a/@version-id = 0.4 returns true
> but  /a/@version-id = 0.4 returns false

For the first case not to be an error you mush hav edefined the prefix 
"default" to be http://example.com
The second case is as would be expected as there is no no-namespace 
element with local name a at the top level.
/b/@version-id=0.4 would also be false.

> In XPath 2.0
> /default:a/@version-id = 0.4 returns an error (prefix not bound)
> and  /a/@version-id = 0.4 returns true

You must have set the default xpath namepsace somewhere (and not defined 
the namespace binding for the prefix default:)
so you only get those results depending on code you have not shown, and 
you would get the same results as xpath 1 by default.

> (I tried these out in Oxygen and I trust the results)
> In my own case I'd start off with XPath 1.0 as it is there out-of-the-box
> in my particular toolbase but later I would imagine there might be a
> reason to progress to XPath 2.0. It would look to me is if all the XPaths
> would need review in that case and some awkward gotchas might occur
> and developers might have to learn about lots of subtle and barely explicable
> nuances and differences between the versions, etc.

the places where xpath2 gives different results are rather slight 9and 
even less if xpath2 is used in backward compatibility mode.
The example you gave is not one of them.
/a/@version-id = 0.4 returns false
will be the xpath 2 behaviour unless you use the (xpath 2) feature of 
changing the default xpath namespace.

>  I'd be reluctant to
> encumber them with this by chosing this approach to validating the XML
> beyond what I get with XSD but overall there doesn't seem to be an
> easier/better alternative so I'd probably still go ahead.
> ----
> Stephen D Green

The fact that changing a language from version 1 to version 2 might have 
some problems in edge cases is not really related to xpath though, you 
would get differences changing from xsd 1.0 to 1.1 or even just between 
xsd processors as they tend to implement darker corners of the xsd spec 


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS