This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 3787 - [XQuery] Code example I.4 with flaws
Summary: [XQuery] Code example I.4 with flaws
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 1.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Don Chamberlin
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-02 21:13 UTC by Hans-Juergen Rennau
Modified: 2006-10-11 22:38 UTC (History)
0 users

See Also:


Attachments

Description Hans-Juergen Rennau 2006-10-02 21:13:24 UTC
[XQuery] The function local:swizzle as described by the appendix has two flaws:

a) text nodes are ignored, thus producing an output document without any text contents
b) no care is taken to ensure that within an element constructor all attribute nodes are written before any element nodes, thus inviting runtime errors 
   
(a) could be solved by replacing the line
         { for $c in $e/(* | @*) return local:swizzle($c) }
by the line
         { for $c in $e/(node() | @*) return local:swizzle($c) }
         
(b) could be taken care of by adding a textual remark, e.g. something of this sort: 

"For the sake of simplicity, the sample code neglects to ensure that 
within an element constructor all attribute nodes are written before 
any element nodes. For example, it relies on <size> elements to have no preceding sibling elements."

However, maybe it would be better to present safe code by just replacing the line
         { for $c in $e/(* | @*) return local:swizzle($c) }
by
         { for $c in ( $e/@* except $e/@color,    (: attribute -> attribute :)
                       $e/size,                   (: elem -> attribute :)
                       $e/@color,                 (: attribute -> elem :)
                       $e/node() except $e/size ) (: elem -> elem :) 
           return local:swizzle($c) }
Comment 1 Don Chamberlin 2006-10-11 22:37:54 UTC
Hans-Juergen,
Good catch! Thanks for notifying the working group of these errors. The next version of the XQuery specification will include the "safe code" corrections that you have proposed. Since the working group has accepted your suggestion in its entirety, I have changed the status of this bug to "Fixed and Closed."
Regards,
Don Chamberlin (for the Query Working Group)