Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-1759

XMLSERIALIZE operator doesn't follow SQL/XML spec in some areas when serializing a sequence.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.2.1.6, 10.2.2.0, 10.3.1.4
    • 10.2.2.0, 10.3.1.4
    • SQL
    • None
    • Urgent

    Description

      The SQL/XML specification dictates that, when serializing a sequence of XML items, the XMLSERIALIZE operator must first "normalize" the sequence based on the rules defined here:

      http://www.w3.org/TR/xslt-xquery-serialization/#serdm

      The current Derby implementation doesn't perform such normalization, which leads to two ways in which the results of an XMLSERIALIZE operator may not agree with the required behavior:

      1. Sequences of atomic values will not have spaces between, but
      the space is required as part of step 3 of the normalization
      rules at the above link.

      2. Derby will allow serialization of a sequence even if it has
      a top-level Attribute node in it, but the rules of normalization
      dictate that an error should be thrown instead (step 7).

      Both of these behaviors can be seen with the following query.

      values
      xmlserialize(
      xmlquery('/ageinfo/@*' passing by ref
      xmlparse(
      document '<ageinfo age="48" birthdate="1900-02-08"/>'
      preserve whitespace
      )
      empty on empty
      )
      as char(50)
      )

      Derby will currently return the following result from this statement:

      1
      --------------------------------------------------
      481900-02-08

      This result does not abide by SQL/XML specification because a) Derby allowed serialization of a sequence having a top-level attribute node (actually, the sequence had two), and b) the atomic values produced from the attributes were displayed without a space between them.

      The correct behavior for the above example is to return a serialization error caused by the presence of an Attribute node in the sequence.

      If the example was rewritten as, say:

      • xmlquery('/ageinfo/@*' passing by ref
        + xmlquery('fn:data(/ageinfo/@*)' passing by ref

      then the attribute nodes are no longer present--we only have their atomic values, which is allowed. Thus the correct result should then be:

      1
      --------------------------------------------------
      48 1900-02-08

      Note, though, that Xalan doesn't appear to support the "fn:data" function, so this rewritten query won't actually work. I tried using Xalan's built-in string function, as follows:

      • xmlquery('/ageinfo/@*' passing by ref
        + xmlquery('string(/ageinfo/@*)' passing by ref

      but Xalan only returns the first attribute in that case; it doesn't return the second one. So part of this Jira issue is probably going to involve figuring out how to allow a user to retrieve a sequence of attribute values (as opposed to attribute nodes) using Xalan and still abide by the SQL/XML rules.

      Attachments

        1. d1759_v1.patch
          35 kB
          A B
        2. d1759_v1.stat
          0.7 kB
          A B

        Issue Links

          Activity

            People

              army A B
              army A B
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: