Results 1 to 2 of 2

Thread: xmlpatterns issues or lack of understanding XQuery?

  1. #1
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question xmlpatterns issues or lack of understanding XQuery?

    Hi all,

    this is gonna be somewhat longish - thx for your consideration.

    I have written an XQuery that works fine in XMLSpy 2007 rel. 3 Enterprise (native Windows), but doesn't with xmlpatterns version 0.1 using Qt 4.7.1 (SLES-10) unless considerably tweaked. The question I have is: Are these issues of Qt xmlpatterns', or is it just my fault/lack of understanding? Also, should my solution be clumsy, please feel free to propose enhancements.

    I should mention that I managed to work around these issues to reach my goal for the time being, yet the nature of this post is not purely academic.

    I will first post the original query, then name the issues and tweaks. In the zip attached you will find the .xq file (containing both the original and the tweaked version) and the data it is meant to work on (actually an .xsd file edit: that I do not have control over).

    The query should be executed like this (the last param is obsolete edit: until one wants to access a single attribute rather than the element sequence; see below):
    Qt Code:
    1. xmlpatterns test.xq -param fileToOpen=CSBF_V_1_3.xsd -param dottedPath=Angebot.Bieter.ARGE_Mitglied.NUTS -param attrName=type
    To copy to clipboard, switch view to plain text mode 
    and it should return, in order, this sequence (abbreviated for clarity):
    Qt Code:
    1. <xsd:element name="Angebot" .../>
    2. <xsd:element name="Bieter" .../>
    3. <xsd:element name="ARGE_Mitglied" .../>
    4. <xsd:element name="NUTS" .../>
    To copy to clipboard, switch view to plain text mode 
    that is, the schema elements according to the "dottedPath" parameter.

    This is the query that works in XMLSpy:
    Qt Code:
    1. xquery version "1.0";
    2.  
    3. declare namespace csbf= "http://www.foo.de/csbf";
    4. declare namespace xsd = "http://www.w3.org/2001/XMLSchema";
    5. declare variable $fileToOpen as xs:anyURI external;
    6. declare variable $inDoc as document-node() := doc($fileToOpen);
    7. declare variable $dottedPath as xs:string external;
    8. declare variable $attrName as xs:string external;
    9.  
    10. (:
    11. This is ok for XMLSpy, but Qt xmlpatterns complains about the leading dot in
    12. 'let $e := ." (Error XPDY0002 [...] The focus is undefined.).
    13. We therefore provide a variant to overcome this issue (see below).
    14. :)
    15. declare function csbf:schema-path($names as xs:string*) as element()*
    16. {
    17. if ( empty($names) )
    18. then ()
    19. else
    20. let $e := .[last()]/child::xsd:sequence/child::xsd:element[@name=$names[1]]
    21. let $complexTypeDef := $inDoc//xsd:complexType[@name=$e/@type/string()]
    22. let $anchor := if ( exists($complexTypeDef ) )
    23. then $complexTypeDef
    24. else $e/xsd:complexType
    25. return ( $e , $anchor/csbf:schema-path(subsequence($names, 2)) )
    26. };
    27.  
    28. $inDoc//xsd:schema/xsd:element/xsd:complexType/csbf:schema-path(tokenize($dottedPath, '\.'))
    To copy to clipboard, switch view to plain text mode 

    The issues are:
    (1) See function comment: Qt xmlpatterns doesn't set the context/focus dynamically and complains about the dot. I can work around this by adding another function parameter (see below).
    (2) The resulting sequence is not in-order, but like this:
    Qt Code:
    1. <xsd:element name="Angebot" .../>
    2. <xsd:element name="ARGE_Mitglied" .../>
    3. <xsd:element name="NUTS" .../>
    4. <xsd:element name="Bieter" .../>
    To copy to clipboard, switch view to plain text mode 
    The element "Bieter" supposed to be second comes last. (Oops, can't [COLOR] inside [CODE] here?)
    (3) (minor) xmlpattern warns that $attrName was not used. This can be worked around by adding
    Qt Code:
    1. declare variable $attr as xs:string := $attrName;
    To copy to clipboard, switch view to plain text mode 
    and use that instead.

    This is the tweaked query that works with both XMLSpy and xmlpatterns:
    (edit: order is still incorrect, but workaround shown - see text below)
    Qt Code:
    1. xquery version "1.0";
    2.  
    3. declare namespace csbf= "http://www.foo.de/csbf";
    4. declare namespace xsd = "http://www.w3.org/2001/XMLSchema";
    5. declare variable $fileToOpen as xs:anyURI external;
    6. declare variable $inDoc as document-node() := doc($fileToOpen);
    7. declare variable $dottedPath as xs:string external;
    8. declare variable $attrName as xs:string external;
    9.  
    10. (:
    11. Variant for Qt xmlpatterns compliance (see above).
    12. :)
    13. declare function csbf:schema-path($e as element(), $names as xs:string*) as element()*
    14. {
    15. if ( empty($names) )
    16. then ()
    17. else
    18. let $e := $e/child::xsd:sequence/child::xsd:element[@name=$names[1]]
    19. let $complexTypeDef := $inDoc//xsd:complexType[@name=$e/@type/string()]
    20. let $anchor := if ( exists($complexTypeDef ) )
    21. then $complexTypeDef
    22. else $e/xsd:complexType
    23. return ( $e , $anchor/csbf:schema-path($anchor, subsequence($names, 2)) )
    24. (: return insert-before( $anchor/csbf:schema-path($anchor, subsequence($names, 2)), 1, $e ) :)
    25. };
    26.  
    27. let $names := tokenize($dottedPath, '\.')
    28. let $parent := $inDoc//xsd:schema/xsd:element/xsd:complexType
    29. (:this returns the element sequence. comment out for attribute access.:)
    30. return csbf:schema-path($parent, $names)
    31.  
    32. (:this returns the attribute value. uncomment as needed.:)
    33. (:let $schema-element := $parent/csbf:schema-path($parent, tokenize($dottedPath, '\.'))[@name=$names[last()]]
    34. return $schema-element/@*[name()=$attrName]/string():)
    To copy to clipboard, switch view to plain text mode 

    Since for now I need only access the cardinality, and the "dottedPath" tokens are presumably distinct, I can work around the second issue as shown in the above code (currently commented) accessing the element by name. However, this is not robust, and the assumption may fail in the future.

    Any enlightenment is very much appreciated!
    Attached Files Attached Files
    Last edited by zaphod.b; 6th January 2011 at 14:05.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: xmlpatterns issues or lack of understanding XQuery?

    You should check your query against some reference implementation of XQuery to be sure whether it is Qt's version that is wrong or maybe the one in XMLSpy. Qt's implementation is certainly incomplete so I wouldn't be suprised if it didn't handle some of the special or rare situations.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 10th November 2010, 07:53
  2. sometime lack string (QtEmbedded Qt4.5, linux)
    By muny in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2009, 16:51
  3. Lack of icons and standard C++ libraries
    By Trok in forum Installation and Deployment
    Replies: 0
    Last Post: 18th June 2009, 22:54
  4. XQuery indexing
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 7th June 2009, 09:20
  5. Tree selection - icon transparency (lack of)
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2008, 21:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.