Difference between revisions of "WebSend (XmlDoc subroutine)"

From m204wiki
Jump to navigation Jump to search
m
m
Line 17: Line 17:
 
<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 of the following options (but no repeats), which are identified below and described in greater detail in [[XmlDoc API serialization options|"XmlDoc API serialization 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>
+
<ul>  
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.
+
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br>
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>
+
Whether or not the serialization will contain the "XML Declaration" (<code><?xml version=...?></code>), if the value of the [[Version (XmlDoc property)|Version]] property is a non-null string, if the <var>XmlDoc</var> is not empty,
<i>n</i> is a non-negative integer, and its maximum value (as of ''Sirius Mods'' version 7.0) is 254.
+
and if the node selected by <var class="term">xpath</var> is the <var>Root</var> node. <var>AllowXmlDecl</var> is the default.  
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>
+
<li><b>Indent <i>n</i></b><br>
<table class="syntaxNested">
+
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 <code>CR</code>, <code>LF</code>, <code>CRLF</code>, or <code>Newline</code> (see below).
<tr><th>CR</th>
+
If <var>Indent</var> is specified and no line-end options are also specified, <var>Newline</var> is implied.
<td>Insert a carriage-return character as the line-end sequence in the above cases. </td></tr>
+
 
<tr><th>LF</th>
+
<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 ''Janus Web'' connection)<br>
<td>Insert a linefeed character as the line-end sequence in the above cases. </td></tr>
+
Inserts one of these line-end options to provide line breaks in the serialized output.  
<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>
+
<li><b>NoEmptyElt</b><br>
<tr><th>Newline</th>
+
Deprecated as of ''Sirius Mods'' 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>).
<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>
+
<li><b>OmitNullElement</b><br>
<p class="code"><br> <li><b>NoEmptyElt</b>
+
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.
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.
+
<li><b>SortCanonical</b><br>
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>
+
This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering).
Here is the display of the <var>XmlDoc</var> with the OmitNullElement option specified: <pre>    <top>        <middle>        </middle>    </top> </pre>
+
It is superseded by the <var>ExclCanonical</var> option.  
The OmitNullElement option is available as of ''Sirius Mods'' version 7.3. <li><b>SortCanonical</b>
+
</ul></td></tr>
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>
 
</table>
  

Revision as of 02:38, 16 February 2011

Serialize XmlDoc as Web response (XmlDoc class)


This subroutine 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 of the following options (but no repeats), which are identified below and 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, if the XmlDoc is not empty, and if the node selected by xpath is the Root node. 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
    Deprecated as of Sirius Mods 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 <middleName/>).
  • 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 ExclCanonical option.

Usage notes

  • The XmlDoc method object must be well-formed (that is, it must contain an Element node). For more information, see "Well-formed documents and validation".
  • 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 version 7.6, this convention was not strictly observed.

Example

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

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


See also

  • Use the Serial function to serialize an XmlDoc for sending in some other fashion than as a Web response.
  • Additional serializing methods include:
  • The function that receives and deserializes a Web XML request is WebReceive.