3
votes

In reference to

Difference between / and /root-node

i am understanding that root node is the same as document node and that the root element is the same as document element. am i understanding it correctly?

can you please confirm that in my sample soap response

  1. S:Envelope is the root node AND the document node
  2. S:Envelope is also the root element AND the document element
  3. will document-node() be the return sequence type of this soap response that i should use in my XQuery declare function signature for the soap request giving this soap response?
  4. or should it be something else like node()*, or item()* or element()*

thanks a lot
apaw

i have this soap response:

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:searchResponse xmlns:ns2="ws.s.b.d.com">
      <return>
        ... snipped ...
        <businessName>GREEN NATURE WATER REFILLING STATION</businessName>
        <province>PROVINCE AA</province>
        <referenceNumber>12345678</referenceNumber>
        ... snipped ...
        <status>Registered</status>
      </return>
      ... snipped a lot of <return> ... </return> ...
      <return>
        ... snipped ...
        <businessName>129 GREEN AVENUE STORE</businessName>
        <province>PROVINCE BB</province>
        <referenceNumber>12345670</referenceNumber>
        ... snipped ...
        <status>Registered</status>
      </return>
    </ns2:searchResponse>
  </S:Body>
</S:Envelope>
1

1 Answers

1
votes

This is a very good question and is often a source of confusion.

In the XDM (XQuery/XPath Data Model), a document node is not the same thing as an element node:

  • A document node encapsulates a whole XML document and is not visible in the syntax.

  • An element node is visible in the syntax as surrounded by angle brackets. S:Envelope is thus an element node.

If the document is parsed with, say, the doc() function, or parse-xml(), what is returned is a document node (type document-node()) and the element S:Envelope (type element() or element(S:Envelope)) will be a child of this document node. I think it would be advisable to stick to this convention for user-defined functions as well.

(Note: other functions may give you a tree without the top-level document node, in which case the tree is called a fragment rather than a document.)

Many different wordings exist for qualifying an element node that is a child of a document node. In the XML infoset, S:Envelop would be called a document element because it is the top-level element information item right under the document information item. But the root itself is the document, not the document element.

Regarding the statement that a root node is a document node and a root element the document element, this requires caution. If the tree is a fragment, the root node will not be a document node (see this part of the XDM specification) but an element node. root element is not an official terminology in either data model.

In short, to address the bullet points:

  1. S:Envelope is the root node AND the document node: no and no if the tree is a document (e.g., obtained with doc()), yes and no if the tree is a fragment.
  2. S:Envelope is also the root element AND the document element: no and yes if the tree is a document, yes and no if it is a fragment.
  3. will document-node() be the return sequence type of this soap response that i should use in my xquery declare function signature for the soap request giving this soap response: It depends if what this function returns is S:Envelope itself, or a document node that wraps it.