WebSend (XmlDoc subroutine): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(26 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:XmlDoc:WebSend subtitle}}
{{Template:XmlDoc:WebSend subtitle}}
<var>WebSend</var> converts an <var>XmlDoc</var> to its textually represented XML document to be sent in a response on a <var class="product">[[Janus Web Server|Janus Web Server]]</var> thread. The process of converting to a text string is called '''serialization''', because the text representation of a document is called the '''serial'''
form.


This subroutine converts an <var>XmlDoc</var> to its textually represented XML document
The serialized output of <var>WebSend</var> is a UTF-8 text string. This output is added to the output buffer that is sent by a subsequent invocation of <var>[[$Web_Done]]</var> or <var>[[$Web_Form_Done]]</var>.
to be sent in a response on a [[Janus Web Server]] thread.
(The process of converting to a text string is called '''serialization''',
because the text representation of a document is called the '''serial'''
form).


The serialized output of <var>WebSend</var> is a UTF-8 text string.
This output is added to the output buffer that is sent by a subsequent
invocation of $Web_done or $Web_form_done.
==Syntax==
==Syntax==
{{Template:XmlDoc:WebSend syntax}}
{{Template:XmlDoc:WebSend syntax}}
Line 16: Line 11:
<tr><th>doc</th>
<tr><th>doc</th>
<td>An expression that points to the <var>XmlDoc</var> whose content is to be serialized. </td></tr>
<td>An expression that points to the <var>XmlDoc</var> whose content is to be serialized. </td></tr>
<tr><th>options</th>
<tr><th>options</th>
<td>Any combination of the following options (but single occurrences only): <ul> <li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b>
<td>A blank delimited string that can contain one or more (but no duplications) of the following options.
<p class="code">AllowXmlDecl, the default, produces the XML declaration (that is, <?xml&thinsp.version=...?>) if the declaration was set (see [[Version (XmlDoc property)|Version]]). NoXmlDecl indicates that the XML declaration is not produced. <li><b>Indent</b> <i><b>n</b></i>
<p class="note">'''Note:''' These options are described in greater detail in [[XmlDoc API serialization options|"XmlDoc API serialization options"]]. </p>
Inserts space characters (and line-ends, as described for the next option) into the serialized string such that if the string is broken 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.
<ul>  
For example, <tt>Indent 2</tt> would produce spacing like the following: <pre>    <top>      <leaf1 xx="yy">value</leaf1>      <sub>        <leaf2>value</leaf2>      </sub>    </top> </pre>
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br>
<i>n</i> is a non-negative integer, and its maximum value (as of ''Sirius Mods'' version 7.0) is 254.
Whether or not the serialization will contain the "XML Declaration" (<code><?xml version=...?></code>), if the value of the <var>[[Version (XmlDoc property)|Version]]</var> property is a non-null string, and if the <var>XmlDoc</var> is not empty. <var>AllowXmlDecl</var> is the default. </li>
Indent may be used with one of the line-end options, above, including Newline. If Indent is specified and no line-end options are also specified, Newline is implied. <li>One of the '''line-end options''' below, to provide line breaks in the output after any of the following is serialized: <ul> <li>An element start-tag, if it has any non-text node children <li>An empty element tag, or an empty element end-tag <li>A processing instruction (PI) <li>A comment <li>A text node, if it has any siblings </ul>
</p>
<table class="syntaxNested">
<tr><th>CR</th>
<td>Insert a carriage-return character as the line-end sequence in the above cases. </td></tr>
<tr><th>LF</th>
<td>Insert a linefeed character as the line-end sequence in the above cases. </td></tr>
<tr><th>CRLF</th>
<td>Insert a carriage-return character followed by a linefeed character as the line-end sequence in the above cases. </td></tr>
<tr><th>Newline</th>
<td>Insert the line-end sequence defined for this [[Janus Web Server]] connection (by the JANUS DEFINE command or $WEB_SET) as the line-end sequence in the above cases. </td></tr>
</table>
<p class="code"><br> <li><b>NoEmptyElt</b>
This indicates that an empty element is serialized with its start tag followed by an end tag. For example: <pre>     <middleName></middleName> </pre> If this option is not specified, the default is to serialize an empty element with an empty element tag: <pre>    <middleName/> </pre> <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.
If an Element node has no Attributes, but has (only) Element children (one or more), and all of its children are Attribute-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 the Serial method display of an <var>XmlDoc</var> in tree format is the following when OmitNullElement is ''not'' specified: <pre>    <top>        <middle>          <empty/>          <p:empty2 xmlns:p="uri:stuff"/>       </middle>     </top> </pre>
Here is the display of the <var>XmlDoc</var> with the OmitNullElement option specified: <pre>    <top>        <middle>        </middle>    </top> </pre>
The OmitNullElement option is available as of ''Sirius Mods'' version 7.3. <li><b>SortCanonical</b>
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, when using the Serial method 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 <var>Unicode</var> code ordering (for example, numbers are lower than letters).
Added in ''Sirius Mods'' version 6.9 as a step towards support for canonicalization, this option is superseded by the Serial method ExclCanonical option ([[??]] refid=exclcan.), which provides full support for canonicalized serialization. </ul></td></tr>
</p>
</table>
==Usage notes==


<ul>
<li><b>Indent <i>n</i></b><br>
<li>The <i><var>XmlDoc</var></i> method object must be well-formed (that is,
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).
it must contain an Element node).
If <var>Indent</var> is specified and no line-end options are also specified, <var>Newline</var> is implied. </li>
For more information about well-formed documents, see [[??]] refid=welform..
<li>The output line-breaking ''options'' make the serialized stream
easier to read, for example, for a browser's "view page source" facility
to display XHTML produced with [[Janus SOAP]].
<li>As of version 6.7, the <var>WebSend</var> method uses the hexadecimal
character references specified in the XML Canonicalization specification
(:hp0 color=SirLink.http://www.w3.org/TR/xml-c14n:ehp0.)  to
display the following characters:
<ul>
<li>For Attribute nodes: tab, carriage return, and linefeed
<li>For Text nodes: carriage return
</ul>


Since the character references are not subject to the standard XML whitespace
<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>
normalization ([[??]] refid=normwhi.),
Inserts one of these line-end options to provide line breaks in the serialized output. </li>
a serialized document (or subtree) that is then deserialized
will retain this whitespace.


These character references are used:
<li><b>NoEmptyElt</b><br>
<dl>
This deprecated option serializes all empty elements 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>).
<dt>tab
<p>
<dd>&amp;#x9;
<var>NoEmptyElt</var> is deprecated in order to deter users from using it to serialize HTML: The recommended approach for HTML is shown on the <var>[[NoEmptyElement (XmlNode property)#browserExample|NoEmptyElement]]</var> property page &mdash; some tags (<code>&#x3c;div></code>) <b>require</b> separate start and end tags, while other tags (<code>&#x3c;br></code>) <b>do not allow</b> separate start and end tags. </p></li>
<dt>CR
<dd>&amp;#xD;
<dt>LF
<dd>&amp;#xA;
</dl>


The EBCDIC and corresponding ASCII encodings of the characters is:
<li><b>OmitNullElement</b><br>
<dl>
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>
<dt>&thinsp.
<dd>EBCDIC    ASCII
<dt>tab
<dd>X'05'          X'09'
<dt>CR
<dd>X'0D'          X'0D'
<dt>LF
<dd>X'25'          X'0A'
</dl>
<li>As of ''Sirius Mods'' version 7.6, ''Attribute values'' are always serialized
within double-quotation-mark (<tt>"</tt>) delimiters,
and a double-quotation mark character in an attribute value is serialized
as <tt>&amp;quot;</tt>.
Prior to version 7.6, this convention was not strictly observed.


<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. </li>
</ul>
</ul>
===Example===
</td></tr>
</table>


The following [[Janus Web Server]] program uses
==Usage notes==
WebReceive to obtain the XML document from the HTTP request,
<ul>
then uses <var>WebSend</var> to buffer some of the received data:
<li>The method object, <var class="term">doc</var>, must be [[XML processing in Janus SOAP#Well-formed documents and validation|well-formed]] (that is, it must contain an <var>Element</var> node).
<p class="code">Begin
<li>The output line-breaking <var class="term">options</var> make the serialized stream easier to read, for example, for a browser's "view page source" facility to display XHTML produced with <var class="product">[[Janus SOAP]]</var>.
%d <var>Object</var> <var>XmlDoc</var>
<li>As of <var class="product">Sirius Mods</var> Version 7.6, <var>Attribute</var> values are always serialized within double-quotation-mark (<tt>"</tt>) delimiters, and a double-quotation mark character in an <var>Attribute</var> value is serialized as <code>&amp;quot;</code>.  Prior to <var class="product">Sirius Mods</var> Version 7.6, this convention was not strictly observed.
%d = New
</ul>
%d:WebReceive
 
%d2 <var>Object</var> <var>XmlDoc</var>
==Examples==
%d2 = New
The following <var class="product">Janus Web Server</var> program uses <var>[[WebReceive_(XmlDoc_function)|WebReceive]]</var> to obtain the XML document from the HTTP request, then uses <var>WebSend</var> to buffer some of the received data:
%d2:LoadXml('<sum>' With -
<p class="code">begin
<p class="code">%d:Value('/*/*[1]') + %d:Value('/*/*[2]') -
  %d object xmlDoc
With '</sum>')
  %d = new
</p>
  %d:webReceive
%d2:<var>WebSend</var>
  %d2 object xmlDoc
End
  %d2 = new
  %d2:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<sum>' with -
      %d:[[Value_(XmlDoc/XmlNode_property)|value]]('/*/*[1]') + %d:value('/*/*[2]') -
      with '</sum>')
  %d2:webSend
end
</p>
</p>


===Request-Cancellation Errors===
==Request-cancellation errors==
This list is not exhaustive: it does <i>not</i> include all the errors that are request  cancelling.
<ul>
<ul>
<li><var>XmlDoc</var> does not contain an Element.
<li>Method object <var class="term">doc</var> does not contain an <var>Element</var>.
<li><i>options</i> is invalid.
<li>An <var class="term">options</var> setting is invalid.
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.
</ul>
</ul>


==See also==
==See also==
{{Template:XmlDoc:WebSend footer}}
<ul>
<li>Use the <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> function to serialize an <var>XmlDoc</var> for sending in some other fashion than as a Web response. </li>


<ul>
<li>Use the [[Serial (XmlDoc/XmlNode function)|Serial]] function to
serialize an <var>XmlDoc</var> for sending in some other fashion than as a Web response.
<li>Additional serializing methods include:
<li>Additional serializing methods include:
<ul>
<ul>
<li>[[Print (XmlDoc/XmlNode subroutine)|Print]]
<li><var>[[Print (XmlDoc/XmlNode subroutine)|Print]]</var> </li>
<li>AddXml (HttpRequest class, described in the [[Janus Sockets]]R.)
 
</ul>
<li><var>[[Audit (XmlDoc/XmlNode subroutine)|Audit]]</var>, <var>[[Trace (XmlDoc/XmlNode subroutine)|Trace]]</var> </li>
<li>The function that receives and deserializes a Web XML request is
 
??[[WebReceive (XmlDoc function)|WebReceive]].
<li><var>[[AddXml (HttpRequest subroutine)|AddXml]]</var> (<var>[[HttpRequest class|HttpRequest]]</var> class) </li>
</ul> </li>
 
<li>For additional discussion about serialization, see [[XmlDoc API#Transport: receiving and sending XML|Transport: receiving and sending XML]].</li>
 
<li>The function that receives and deserializes a Web XML request is <var>[[WebReceive (XmlDoc function)|WebReceive]]</var>. </li>
</ul>
</ul>
{{Template:XmlDoc:WebSend footer}}

Latest revision as of 21:08, 18 March 2014

Serialize XmlDoc as Web response (XmlDoc class)

WebSend converts an XmlDoc to its textually represented XML document to be sent in a response on a Janus Web Server thread. The process of converting to a text string is called serialization, because the text representation of a document is called the serial form.

The serialized output of WebSend is a UTF-8 text string. This output is added to the output buffer that is sent by a subsequent invocation of $Web_Done or $Web_Form_Done.

Syntax

doc:WebSend[( [options])]

Syntax terms

doc An expression that points to the XmlDoc whose content is to be serialized.
options A blank delimited string that can contain one or more (but no duplications) of the following options.

Note: These options are described in greater detail in "XmlDoc API serialization options".

  • AllowXmlDecl or NoXmlDecl
    Whether or not the serialization will contain the "XML Declaration" (<?xml version=...?>), if the value of the Version property is a non-null string, and if the XmlDoc is not empty. AllowXmlDecl is the default.
  • Indent n
    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 CR, LF, CRLF, or Newline (see below). If Indent is specified and no line-end options are also specified, Newline is implied.
  • CR (carriage-return), LF (linefeed), CRLF (carriage-return followed by a linefeed), or Newline (line-end set for the Janus Web connection)
    Inserts one of these line-end options to provide line breaks in the serialized output.
  • NoEmptyElt
    This deprecated option serializes all empty elements with a start tag followed by an end tag. The default is to serialize an empty element with an empty element tag (as in <middleName/>).

    NoEmptyElt is deprecated in order to deter users from using it to serialize HTML: The recommended approach for HTML is shown on the NoEmptyElement property page — some tags (<div>) require separate start and end tags, while other tags (<br>) do not allow separate start and end tags.

  • OmitNullElement
    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.
  • SortCanonical
    This deprecated option, serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). It is superseded by the Serial method ExclCanonical option.

Usage notes

  • The method object, doc, must be well-formed (that is, it must contain an Element node).
  • The output line-breaking options make the serialized stream easier to read, for example, for a browser's "view page source" facility to display XHTML produced with Janus SOAP.
  • As of Sirius Mods Version 7.6, Attribute values are always serialized within double-quotation-mark (") delimiters, and a double-quotation mark character in an Attribute value is serialized as &quot;. Prior to Sirius Mods Version 7.6, this convention was not strictly observed.

Examples

The following Janus Web Server program uses WebReceive to obtain the XML document from the HTTP request, then uses WebSend to buffer some of the received data:

begin %d object xmlDoc %d = new %d:webReceive %d2 object xmlDoc %d2 = new %d2:loadXml('<sum>' with - %d:value('/*/*[1]') + %d:value('/*/*[2]') - with '</sum>') %d2:webSend end

Request-cancellation errors

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • Method object doc does not contain an Element.
  • An options setting is invalid.
  • Insufficient free space exists in CCATEMP.

See also