AddXml (HttpRequest subroutine): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 12: | Line 12: | ||
<td>A previously defined and instantiated <var>HTTPRequest</var> object. | <td>A previously defined and instantiated <var>HTTPRequest</var> object. | ||
</td></tr> | </td></tr> | ||
<tr><th> | <tr><th>doc</th> | ||
<td>An XmlDoc object that contains an instantiated XmlDoc object. | <td>An XmlDoc object that contains an instantiated XmlDoc object. | ||
</td></tr> | </td></tr> | ||
Line 19: | Line 19: | ||
<ul> | <ul> | ||
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b> | <li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b> | ||
AllowXmlDecl, the default, produces the XML declaration (that is, <?xml | AllowXmlDecl, the default, produces the XML declaration (that is, <code><?xml version=...?></code>) if the declaration was already defined in <var class="term">doc</var>. <var>NoXmlDecl</var> omits the XML declaration. | ||
<li><b>Indent</b> <i><b>n</b></i> | <li><b>Indent</b> <i><b>n</b></i> | ||
The display of each lower level in the serialized subtree is indented ''n'' spaces from the previous level's starting point, where <i>n</i> is a non-negative integer. | The display of each lower level in the serialized subtree is indented ''n'' spaces from the previous level's starting point, where <i>n</i> is a non-negative integer. | ||
This option may be used with one of the line-end options, below, including Newline. If Indent is specified and no line-end options are also specified, Newline is implied. | This option may be used with one of the line-end options, below, including <var>Newline</var>. If <var>Indent</var> is specified and no line-end options are also specified, <var>Newline</var> is implied. | ||
Indent 2 (with a line-end option) would produce: <p class="code"> <top> <leaf1 xx="yy">value</leaf1> <sub> <leaf2>value</leaf2> </sub> </top> </p> <li>One of the '''line-end options''' below, to provide line breaks in the output after any of the following in | <code>Indent 2</code> (with a line-end option) would produce: <p class="code"> <top> <leaf1 xx="yy">value</leaf1> <sub> <leaf2>value</leaf2> </sub> </top> </p> <li>One of the '''line-end options''' below, to provide line breaks in the output after any of the following in <var class="term">doc</var> is serialized: | ||
<ul> <li>An element start-tag, if it has any non-text node children | <ul> <li>An element start-tag, if it has any non-text node children | ||
Line 35: | Line 35: | ||
<li><b>NoEmptyElt</b> | <li><b>NoEmptyElt</b> | ||
This indicates that an empty element in | This indicates that an empty element in <var class="term">doc</var> is serialized with its start tag followed by an end tag. For example: <p class="code"> <middleName></middleName> </p> If this option is not specified, the default is to serialize an empty element with an empty element tag: <p class="code"> <middleName/> </p> <li><b>OmitNullElement</b> | ||
An Element node that has no children and no Attributes will not be serialized, unless it is the top level Element in the subtree being serialized. The serialization of a child-less and Attribute-less Element is omitted, even if the Element's serialization would contain Namespace declarations in its start tag. | An Element node that has no children and no Attributes will not be serialized, unless it is the top level Element in the subtree being serialized. The serialization of a child-less and Attribute-less Element is omitted, even if the Element's serialization would contain Namespace declarations in its start tag. | ||
If an Element node has no Attributes, but has (only) Element children (one or more), and all of its children are Attibute-less and child-less, then that parent Element is serialized, even though its content in the serialization is empty. That parent is serialized with a start tag and an end tag (and an inserted line separator, if called for by the serializing method's parameter options). | If an Element node has no Attributes, but has (only) Element children (one or more), and all of its children are Attibute-less and child-less, then that parent Element is serialized, even though its content in the serialization is empty. That parent is serialized with a start tag and an end tag (and an inserted line separator, if called for by the serializing method's parameter options). | ||
For example, if a tree display of | For example, if a tree display of <var class="term">doc</var> is the following when OmitNullElement is ''not'' specified: | ||
<p class="code"> <top> <middle> <empty/> <p:empty2 xmlns:p="uri:stuff"/> </middle> </top> </p> | <p class="code"> <top> <middle> <empty/> <p:empty2 xmlns:p="uri:stuff"/> </middle> </top> </p> | ||
This is the display of | This is the display of <var class="term">doc</var> with the OmitNullElement option specified: | ||
<p class="code"> <top> <middle> </middle> </top> </p> | <p class="code"> <top> <middle> </middle> </top> </p> | ||
The OmitNullElement option is available as of <var class="product">Sirius Mods</var> version 7.3. | The OmitNullElement option is available as of <var class="product">Sirius Mods</var> version 7.3. | ||
Line 47: | Line 47: | ||
This indicates that namespace declarations (based on the prefix being declared) and attributes (based on the namespace URI followed by the local name) are serialized in sorted order. This can be useful, for instance, to serialize a portion of an XML document for a signature. | This indicates that namespace declarations (based on the prefix being declared) and attributes (based on the namespace URI followed by the local name) are serialized in sorted order. This can be useful, for instance, to serialize a portion of an XML document for a signature. | ||
The sort order for namespace declarations and attributes is from lowest to highest, and it uses the Unicode code ordering (for example, numbers are lower than letters). | The sort order for namespace declarations and attributes is from lowest to highest, and it uses the Unicode code ordering (for example, numbers are lower than letters). | ||
This option was added in <var class="product">Sirius Mods</var> version 6.9 as a step towards support for canonicalization. As of version 7.0, comprehensive support for canonicalized serialization is provided (only) by the Serial method | This option was added in <var class="product">Sirius Mods</var> version 6.9 as a step towards support for canonicalization. As of version 7.0, comprehensive support for canonicalized serialization is provided (only) by the <var>Serial</var> method <var>[[Serial (XmlDoc/XmlNode function)#options|ExclCanonical]]</var> option. <var>SortCanonical</var> is described in greater detail [[#sortcan|below]]. </ul> | ||
</td></tr></table> | </td></tr></table> | ||
Line 57: | Line 57: | ||
<li>Invoking this method erases any post data previously | <li>Invoking this method erases any post data previously | ||
added by <var>AddXML</var> or <var>[[AddLongString (HTTPRequest subroutine)|AddLongString]]</var> method calls. | added by <var>AddXML</var> or <var>[[AddLongString (HTTPRequest subroutine)|AddLongString]]</var> method calls. | ||
<li> | <li>If you do not explicitly set a | ||
content-type HTTP request header via <var>[[AddHeader (HTTPRequest subroutine)|AddHeader]]</var>, | content-type HTTP request header via <var>[[AddHeader (HTTPRequest subroutine)|AddHeader]]</var>, | ||
AddXml generates a content-type header of | AddXml generates a content-type header of "text/xml" upon a Post. | ||
To suppress this automatic header generation, you can set the | To suppress this automatic header generation, you can set the | ||
<var>[[AutoSendXMLContentType (HTTPRequest property)|AutoSendXMLContentType]]</var> property | <var>[[AutoSendXMLContentType (HTTPRequest property)|AutoSendXMLContentType]]</var> property | ||
to False. | to <code>False</code>. | ||
<li>The <i>xmloptions</i> may be specified in any case, for example, you can use | <li>The <i>xmloptions</i> may be specified in any case, for example, you can use | ||
either <code>NoXmlDecl</code> or <code>noxmldecl</code>, interchangeably. | either <code>NoXmlDecl</code> or <code>noxmldecl</code>, interchangeably. | ||
Line 77: | Line 77: | ||
does it cause resumption of readability line-ends or indents if they were | does it cause resumption of readability line-ends or indents if they were | ||
suspended by a containing <code>xml:space="preserve"</code>. | suspended by a containing <code>xml:space="preserve"</code>. | ||
<li> | <li>The AddXml method uses the | ||
character references specified in the XML Canonicalization specification | character references specified in the XML Canonicalization specification | ||
(http://www.w3.org/TR/xml-c14n) to | (http://www.w3.org/TR/xml-c14n) to | ||
display the following characters: | display the following characters: | ||
<ul> | <ul> | ||
<li>For Attribute nodes: tab, carriage return, and linefeed | <li>For <var>Attribute</var> nodes: tab, carriage return, and linefeed | ||
<li>For Text nodes: carriage return | <li>For <var>Text</var> nodes: carriage return | ||
</ul> | </ul> | ||
Line 111: | Line 111: | ||
For more information about XML document whitespace handling, see [[XML processing in Janus SOAP#Normalizing whitespace characters|"Normalizing whitespace characters"]]. | For more information about XML document whitespace handling, see [[XML processing in Janus SOAP#Normalizing whitespace characters|"Normalizing whitespace characters"]]. | ||
<div id="sortcan"></div> | |||
<li>The following example shows the effect of the <var>SortCanonical</var> option:<p class="code"> Begin | <li>The following example shows the effect of the <var>SortCanonical</var> option:<p class="code"> Begin | ||
%d is object Xmldoc | %d is object Xmldoc | ||
Line 130: | Line 131: | ||
End </p> | End </p> | ||
The <var>Print</var> statement above (which uses the <var>[[Serial (XmlDoc/XmlNode function)]]</var> method of the <var class="product>[[Janus SOAP]]</var> [[XmlDoc API]]) displays the resulting <var>XmlDoc</var> content added to the <var>HTTPRequest</var> object (formatted with some newlines for the sake of instruction): <p class="code"><top | The <var>Print</var> statement above (which uses the <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> method of the <var class="product>[[Janus SOAP]]</var> [[XmlDoc API]]) displays the resulting <var>XmlDoc</var> content added to the <var>HTTPRequest</var> object (formatted with some newlines for the sake of instruction): <p class="code"><top | ||
xmlns="urn:default" | xmlns="urn:default" | ||
xmlns:p="urn:p" xmlns:q="http://q.com" | xmlns:p="urn:p" xmlns:q="http://q.com" | ||
Line 139: | Line 140: | ||
Comments: | Comments: | ||
<ul> | <ul> | ||
<li>The reason for the name (<var>SortCanonical</var>) is that this ordering is part of the specification of the <i><b>Canonical XML Recommendation</b></i> (http://www.w3.org/TR/xml | <li>The reason for the name (<var>SortCanonical</var>) is that this ordering is part of the specification of the <i><b>Canonical XML Recommendation</b></i> (http://www.w3.org/TR/xml-c14n) and the <i><b>Exclusive Canonical XML Recommendation</b></i> (http://www.w3.org/TR/xml-exc-c14n), which constrain serializations to facilitate processing such as digital signatures. | ||
<li>Notice the use of the <var>NoEmptyElt</var> option above. This produces an STag (<code><top ...></code>) and an ETag (<code></top></code>) for an empty element, rather than just the EmptyElemTag (<code><top ...></code>). | <li>Notice the use of the <var>NoEmptyElt</var> option above. This produces an STag (<code><top ...></code>) and an ETag (<code></top></code>) for an empty element, rather than just the EmptyElemTag (<code><top ...></code>). | ||
The canonical XML recommendations state that an STag/ETag pair, rather than an EmptyElemTag, is the serialization for an empty element. | The canonical XML recommendations state that an STag/ETag pair, rather than an EmptyElemTag, is the serialization for an empty element. |
Revision as of 23:44, 15 June 2011
Template:HTTPRequest:AddXML subtitle
This subroutine adds a Janus SOAP XmlDoc object instance to the HTTP Post data that is subsequently sent on a Post method invocation.
Syntax
Template:HTTPRequest:AddXML syntax
Syntax terms
%httpreq | A previously defined and instantiated HTTPRequest object. |
---|---|
doc | An XmlDoc object that contains an instantiated XmlDoc object. |
xmloptions | Any combination of the following options (but single occurrences only):
|
Usage notes
- The XmlDoc that is passed is serialized into the post data of the request being built. It is not required that you serialize the XmlDoc first.
- Invoking this method erases any post data previously added by AddXML or AddLongString method calls.
- If you do not explicitly set a
content-type HTTP request header via AddHeader,
AddXml generates a content-type header of "text/xml" upon a Post.
To suppress this automatic header generation, you can set the
AutoSendXMLContentType property
to
False
. - The xmloptions may be specified in any case, for example, you can use
either
NoXmlDecl
ornoxmldecl
, interchangeably. - If one of the line-end
(
CR
,LF
,CRLF
) options or ifIndent
is specified, and an element to be serialized has thexml:space="preserve"
attribute, then within the serialization of that element and its descendants, no line-end (nor indentation) characters are inserted to provide readability. In addition, thexml:space="default"
attribute has no effect under these options: specified by itself, it does not influence serialization, nor does it cause resumption of readability line-ends or indents if they were suspended by a containingxml:space="preserve"
. - The AddXml method uses the
character references specified in the XML Canonicalization specification
(http://www.w3.org/TR/xml-c14n) to
display the following characters:
- For Attribute nodes: tab, carriage return, and linefeed
- For Text nodes: carriage return
Since the character references are not subject to the standard XML whitespace normalization (so not removed), a serialized document (or subtree) that is then deserialized will retain this whitespace.
These character references are used:
tab 	 CR 
 LF 
 The EBCDIC and corresponding ASCII encodings of the characters is:
EBCDIC ASCII tab X'05' X'09' CR X'0D' X'0D' LF X'25' X'0A' For more information about XML document whitespace handling, see "Normalizing whitespace characters".
- The following example shows the effect of the SortCanonical option:
Begin %d is object Xmldoc %d = new %htr is object HttpRequest %htr = new %sl is object Stringlist %sl = new Text To %sl <top p:abc="p" q:xyz="q" xmlns:p="urn:p" xmlns:q="http://q.com" xmlns="urn:default" name="t" id="z15" /> End Text %d:LoadXml(%sl) %htr:AddXml(%d, 'SortCanonical NoEmptyElt') Print %d:Serial(, 'EBCDIC SortCanonical NoEmptyElt') End
The Print statement above (which uses the Serial method of the Janus SOAP XmlDoc API) displays the resulting XmlDoc content added to the HTTPRequest object (formatted with some newlines for the sake of instruction):<top xmlns="urn:default" xmlns:p="urn:p" xmlns:q="http://q.com" id="z15" name="t" q:xyz="q" p:abc="p" > </top>
Comments:
- The reason for the name (SortCanonical) is that this ordering is part of the specification of the Canonical XML Recommendation (http://www.w3.org/TR/xml-c14n) and the Exclusive Canonical XML Recommendation (http://www.w3.org/TR/xml-exc-c14n), which constrain serializations to facilitate processing such as digital signatures.
- Notice the use of the NoEmptyElt option above. This produces an STag (
<top ...>
) and an ETag (</top>
) for an empty element, rather than just the EmptyElemTag (<top ...>
). The canonical XML recommendations state that an STag/ETag pair, rather than an EmptyElemTag, is the serialization for an empty element. - Although SortCanonical uses the Unicode sort sequence, this is limited to Unicode values less than 256 (as of version 6.9 of Janus SOAP, so it is accomplished with an 8-byte EBCDIC to 8-byte Unicode table, which is (for all intents and purposes) merely an EBCDIC-to-ASCII translation.