[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Concerned about the increasing reliance on XPath

  • From: Stephen D Green <stephengreenubl@gmail.com>
  • To: David Carlisle <davidc@nag.co.uk>
  • Date: Mon, 9 May 2011 16:43:53 +0100

Re:  Concerned about the increasing reliance on XPath
I tried to think of a way to write the XPath expression so
it gives the same result whatever the version of XPath
and it gets rather complex and obscure and not what I'd
be expecting a non-specialist developer to do or understand
well enough to be able to maintain it but it does evaluate
to true whatever the version and maybe (?) whatever the
namespace bindings

/*[local-name()='a']/@version-id = 0.4

What would I have to do to ensure it didn't get the same result
with another default namespace though? I guess I'd have to
make the expression even more complex:

/*[local-name()='a'][namespace-uri()='http://example.com']/@version-id = 0.4

I could hardly expect a nominally XML-savvy developer to
have to understand and maintian this. Then, if the expression
involved more than one element and mutliple namespaces...
----
Stephen D Green



On 9 May 2011 15:49, David Carlisle <davidc@nag.co.uk> wrote:
> 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
> differently.
>
> David
>
> ________________________________________________________________________
> 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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.