Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xml-dev] XPath 2.0 Best Practice Issue: Graceful Degradation

From: "Costello, Roger L." <costello@-----.--->
To: <xml-dev@-----.---.--->
Date: 1/29/2008 2:41:00 PM
Excellent discussion!

Question: Can we create best practices for XPath that are independent
of the host language?


I would like to pursue the ideas that David Carlisle has put forth.
(David, please correct any errors in my representation of your ideas)

Consider this XPath statement:

    if (//airplane[@tailnum='C3H1'] instance of
schema-element(airplane)) then 
            //airplane[@tailnum='C3H1']/altitude * .3048  
    else 
        if (//airplane[@tailnum='C3H1']/altitude[@unit='feet'] castable
as xs:double) then 
            //airplane[@tailnum='C3H1']/altitude * .3048
        else
            'Error'

There are three kinds of activities going on in the XPath statement:

1. There is data processing: the altitude value is converted from feet
to meters: 

    //airplane[@tailnum='C3H1']/altitude * .3048  

2. There is an XPath check: check that there is an airplane element
with a tailnum attribute having the value 'C3H1', and it has a child
altitude element with a unit attribute having the value 'feet', and its
value can be interpreted as an xs:double value:

    if (//airplane[@tailnum='C3H1']/altitude[@unit='feet'] castable as
xs:double) then ...

3. There is a schema-validation check: check that the host language has
schema-validated the input data:

    if (//airplane[@tailnum='C3H1'] instance of
schema-element(airplane)) then ...

The three activities are combined into one XPath statement.

David asserts that best practice is to keep the three activities
separate.

The advantage of keeping them separate is that the XPath will be easier
to read and maintain.

Thus, when you want to compose an XPath statement to convert the
altitude value from feet to meters, you simply write this XPath: 

    //airplane[@tailnum='C3H1']/altitude * .3048

The XPath to perform a schema-validation check and the XPath check
should be done elsewhere.  (This is pretty vague.  Can we better
characterize what this means?  Where would these checks be done?  If we
want "portable XPath statements" -- XPath statements that can be picked
up and dropped into other documents -- how robust would an XPath
statement be if it's separated from its checks?)

Here's a summary of David's proposal:

When designing an XPath statement, do not combine data processing,
XPath checks, and schema-validation checks.  Instead, keep the three
activities separate.

Do you agree with this?

/Roger


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent