AddXml (HttpRequest subroutine): Difference between revisions
mNo edit summary |
m (match syntax table to syntax template; edits, tags and links) |
||
Line 1: | Line 1: | ||
{{Template:HttpRequest:AddXml subtitle}} | {{Template:HttpRequest:AddXml subtitle}} | ||
The <var>AddXml</var> subroutine adds a <var class="product">[[Janus SOAP]]</var> [[XmlDoc_API#The_XmlDoc_class|XmlDoc]] object instance to the HTTP Post data that is subsequently sent on a <var>[[Post (HttpRequest function)|Post]]</var> method invocation. | |||
XmlDoc object instance to the HTTP Post data that is subsequently | |||
sent on a <var>[[Post (HttpRequest function)|Post]]</var> method invocation. | |||
==Syntax== | ==Syntax== | ||
Line 9: | Line 6: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th> | <tr><th>httpRequest</th> | ||
<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>doc</th> | <tr><th>doc</th> | ||
<td> | <td>A previously defined and instantiated <var>XmlDoc</var> object. | ||
</td></tr> | </td></tr> | ||
<tr><th> | <tr><th>options</th> | ||
<td>Any combination of the following options (but single occurrences only): | <td>Any combination of the following options (but single occurrences only): | ||
<ul> | <ul> | ||
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br> | <li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br> | ||
AllowXmlDecl, the default, produces the "XML Declaration" (that is, <code><?xml version=...?></code>) if the value of the <var>[[Version (XmlDoc property)|Version]]</var> property in <var class="term">doc</var> is a non-null string. <var>NoXmlDecl</var> omits the XML declaration. | AllowXmlDecl, the default, produces the "XML Declaration" (that is, <code><?xml version=...?></code>) if the value of the <var>[[Version (XmlDoc property)|Version]]</var> property in <var class="term">doc</var> is a non-null string. <var>NoXmlDecl</var> omits the XML declaration. | ||
<li><b>Indent</b> <i><b>n</b></i><br> | <li><b>Indent</b> <i><b>n</b></i><br> | ||
Inserts space characters and line-ends into the serialized string such that if the string is broken at the line-ends and displayed as a tree, the display of each lower level in the subtree is indented ''n'' spaces from the previous level's starting point. You may also specify <var>CR</var>, <var>LF</var>, <var>CRLF</var>, or <var>Newline</var> (see below). | Inserts space characters and line-ends into the serialized string such that if the string is broken at the line-ends and displayed as a tree, the display of each lower level in the subtree is indented ''n'' spaces from the previous level's starting point. You may also specify <var>CR</var>, <var>LF</var>, <var>CRLF</var>, or <var>Newline</var> (see below). If <var>Indent</var> is specified and no line-end options are also specified, <var>Newline</var> is implied. | ||
If <var>Indent</var> is specified and no line-end options are also specified, <var>Newline</var> is implied. | |||
<li><b>CR</b> (carriage-return), <b>LF</b> (linefeed), <b>CRLF</b> (carriage-return followed by a linefeed), or <b>Newline</b> (line-end set for the <var class="product">Janus Web</var> connection)<br> | <li><b>CR</b> (carriage-return), <b>LF</b> (linefeed), <b>CRLF</b> (carriage-return followed by a linefeed), or <b>Newline</b> (line-end set for the <var class="product">Janus Web</var> connection)<br> | ||
Inserts one of these line-end options to provide line breaks in the serialized output. | Inserts one of these line-end options to provide line breaks in the serialized output. | ||
<li><b>NoEmptyElt</b><br> | <li><b>NoEmptyElt</b><br> | ||
Deprecated as of <var class="product">[[Sirius Mods]]</var> Version 7.0, this option ensures that all empty elements are serialized with a start tag followed by an end tag. The default is to serialize an empty element with an empty element tag (as in <code><middleName/></code>). | Deprecated as of <var class="product">[[Sirius Mods]]</var> Version 7.0, this option ensures that all empty elements are serialized with a start tag followed by an end tag. The default is to serialize an empty element with an empty element tag (as in <code><middleName/></code>). | ||
<li><b>OmitNullElement</b><br> | <li><b>OmitNullElement</b><br> | ||
An <var>Element</var> node that has no children and no <var>Attributes</var> will not be serialized, unless it is the top level <var>Element</var> in the subtree being serialized. | An <var>Element</var> node that has no children and no <var>Attributes</var> will not be serialized, unless it is the top level <var>Element</var> in the subtree being serialized. | ||
<li><b>SortCanonical</b><br> | <li><b>SortCanonical</b><br> | ||
This deprecated option, serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). It is superseded by the <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> method <var>ExclCanonical</var> option. | This deprecated option, serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). It is superseded by the <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> method <var>ExclCanonical</var> option.</ul> | ||
'''Note:''' These options are described in greater detail in [[XmlDoc API serialization options|"XmlDoc API serialization options"]]</td></tr></table> | '''Note:''' These options are described in greater detail in [[XmlDoc API serialization options|"XmlDoc API serialization options"]]. | ||
</td></tr></table> | |||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>The <var>XmlDoc</var> that is passed is serialized into the post data of the request | <li>The <var>XmlDoc</var> that is passed is serialized into the post data of the request being built. It is not required that you serialize the <var>XmlDoc</var> first. | ||
being built. | <li>Invoking this method erases any post data previously added by <var>AddXml</var> or <var>[[AddLongString (HttpRequest subroutine)|AddLongString]]</var> method calls. | ||
It is not required that you serialize the <var>XmlDoc</var> first. | <li>If you do not explicitly set a content-type HTTP request header via <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, <var>AddXml</var> generates a content-type header of "text/xml" upon a Post. To suppress this automatic header generation, you can set the <var>[[AutoSendXmlContentType (HttpRequest property)|AutoSendXmlContentType]]</var> property to <code>False</code>. | ||
<li>Invoking this method erases any post data previously | <li>The <var class="term">options</var> may be specified in any case, for example, you can use | ||
added by <var>AddXml</var> or <var>[[AddLongString (HttpRequest subroutine)|AddLongString]]</var> method calls. | |||
<li>If you do not explicitly set a | |||
content-type HTTP request header via <var>[[AddHeader (HttpRequest subroutine)|AddHeader]]</var>, | |||
AddXml generates a content-type header of "text/xml" upon a Post. | |||
To suppress this automatic header generation, you can set the | |||
<var>[[AutoSendXmlContentType (HttpRequest property)|AutoSendXmlContentType]]</var> property | |||
to <code>False</code>. | |||
<li>The < | |||
either <code>NoXmlDecl</code> or <code>noxmldecl</code>, interchangeably. | either <code>NoXmlDecl</code> or <code>noxmldecl</code>, interchangeably. | ||
<li>If one of the line-end | <li>If one of the line-end (<code>CR</code>, <code>LF</code>, <code>CRLF</code>) options or if <code>Indent</code> is specified, and an element to be serialized has the <code>xml:space="preserve"</code> attribute, then | ||
(<code>CR</code>, <code>LF</code>, <code>CRLF</code>) options or if | within the serialization of that element and its descendants, no line-end (nor indentation) characters are inserted to provide readability. | ||
<code>Indent</code> is specified, and an element to be serialized has the | |||
<code>xml:space="preserve"</code> attribute, then | |||
within the serialization of that element and its descendants, no line-end | |||
(nor indentation) characters are inserted to provide readability. | |||
Additionally, the <code>xml:space="default"</code> 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 containing <code>xml:space="preserve"</code>. | |||
under these options | |||
does it cause resumption of readability line-ends or indents if they were | |||
suspended by a containing <code>xml:space="preserve"</code>. | |||
</ul> | </ul> | ||
<div id="sortcan"></div> | |||
==Examples== | ==Examples== | ||
The following example shows the effect of the <var>NoEmptyElt</var> option:<p class="code"> | <ol><li>The following example shows the effect of the <var>NoEmptyElt</var> option: | ||
%d is object | <p class="code">begin | ||
%d = new | %d is object [[XmlDoc_API#The_XmlDoc_class|xmlDoc]] | ||
%htr is object | %d = [[New_(XmlDoc_constructor)|new]] | ||
%htr = new | %htr is object httpRequest | ||
%sl is object | %htr = [[New_(HttpRequest_constructor)|new]] | ||
%sl = new | %sl is object [[Stringlist_class|stringlist]] | ||
%sl = [[New_(Stringlist_constructor)|new]] | |||
<top p:abc="p" q:xyz="q" | [[Text_and_Html_statements#The_HTML_or_TEXT_statement|text to]] %sl | ||
<top p:abc="p" q:xyz="q" | |||
xmlns:p="urn:p" xmlns:q=<nowiki>"http://q.com"</nowiki> | |||
/> | name="t" id="z15" | ||
/> | |||
%d: | end text | ||
%htr: | %d:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]](%sl) | ||
%htr:addXml(%d, 'NoEmptyElt') | |||
print %d:[[Serial (XmlDoc/XmlNode function)|Serial]](, 'EBCDIC NoEmptyElt') | |||
end | |||
The <var> | </p> | ||
The <var>print</var> statement above (which uses the <var class="product">[[Janus SOAP]]</var> [[XmlDoc API]] <var>serial</var> method) 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:p="urn:p" xmlns:q=<nowiki>"http://q.com"</nowiki> | xmlns:p="urn:p" xmlns:q=<nowiki>"http://q.com"</nowiki> | ||
p:abc="p" q:xyz="q" | p:abc="p" q:xyz="q" | ||
name="t" id="z15"> | name="t" id="z15"> | ||
</top> </p> | </top> | ||
</p> | |||
Comments: | |||
<ul><li> | |||
<var>NoEmptyElt</var> produces an STag (<code><top ...></code>) and an ETag (<code></top></code>) for an empty element, rather than just the EmptyElemTag (<code><top ...></code>). | <var>NoEmptyElt</var> produces an STag (<code><top ...></code>) and an ETag (<code></top></code>) for an empty element, rather than just the EmptyElemTag (<code><top ...></code>). | ||
</ul> | |||
</ol> | |||
==See also== | ==See also== | ||
{{Template:HttpRequest:AddXml footer}} | {{Template:HttpRequest:AddXml footer}} |
Revision as of 07:37, 18 June 2011
Add an XmlDoc to POST data for this request (HttpRequest class)
The AddXml subroutine adds a Janus SOAP XmlDoc object instance to the HTTP Post data that is subsequently sent on a Post method invocation.
Syntax
httpRequest:AddXml( doc, [options])
Syntax terms
httpRequest | A previously defined and instantiated HttpRequest object. |
---|---|
doc | A previously defined and instantiated XmlDoc object. |
options | Any combination of the following options (but single occurrences only):
Note: These options are described in greater detail in "XmlDoc API serialization options". |
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 options 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. Additionally, 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"
.
Examples
- The following example shows the effect of the NoEmptyElt 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" name="t" id="z15" /> end text %d:loadXml(%sl) %htr:addXml(%d, 'NoEmptyElt') print %d:Serial(, 'EBCDIC NoEmptyElt') end
The print statement above (which uses the Janus SOAP XmlDoc API serial method) displays the resulting XmlDoc content added to the HttpRequest object (formatted with some newlines for the sake of instruction):
<top xmlns:p="urn:p" xmlns:q="http://q.com" p:abc="p" q:xyz="q" name="t" id="z15"> </top>
Comments:
-
NoEmptyElt produces an STag (
<top ...>
) and an ETag (</top>
) for an empty element, rather than just the EmptyElemTag (<top ...>
).
-
NoEmptyElt produces an STag (