Serial (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 11: Line 11:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%utfOrEbcd</th>
<tr><th>%utfOrEbcd</th>
<td>A string variable for the string serialization of the subtree, encoded either in UTF-8 or, if the <tt>EBCDIC</tt> option (see below) is used, in EBCDIC. </td></tr>
<td>A string variable for the string serialization of the subtree, encoded either in UTF-8 or, if the <var>EBCDIC</var> option (see below) is used, in EBCDIC. </td></tr>


<tr><th>nr</th>
<tr><th>nr</th>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. If an <var>XmlDoc</var>, the Root node is the context node. </td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">xpath</var> expression. If an <var>XmlDoc</var>, the <var>Root</var> node is the context node. </td></tr>


<tr><th>XPath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> string that is an XPath expression that results in a nodelist, the head of which is the top of the subtree to serialize. This is an optional argument; its default is a period (.), that is, the node referenced by the method object (<i>nr</i>).
<td>A <var>Unicode</var> string that is an [[XML processing in Janus SOAP#XML Path Language (XPath) in the XmlDoc API|XPath]] expression that results in a nodelist, the head of which is the top of the subtree to serialize. This is an optional argument; its default is a period (<tt>.</tt>), that is, the node referenced by the method object (<var class="term">nr</var>).


Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
Line 30: Line 30:
Produces serialized output in exclusive XML canonical form, as defined in the W3C "Exclusive XML Canonicalization" specification (http://www.w3.org/tr/xml-exc-c14n).  
Produces serialized output in exclusive XML canonical form, as defined in the W3C "Exclusive XML Canonicalization" specification (http://www.w3.org/tr/xml-exc-c14n).  


<li><b>Indent</b> <i><b>n</b></i><br>
<li><b>Indent <i>n</i></b><br>
Inserts space characters (and line-ends, as described for the next option) 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.
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 must also specify <code>CR</code>, <code>LF</code>, or <code>CRLF</code> (see below).
<p>
 
One of the line-end options, below, must also be specified.</p>
<li><b>CR</b> (carriage-return), <b>LF</b> (linefeed), or <b>CRLF</b> (carriage-return followed by a linefeed)<br>
<li><b>CR</b> (carriage-return), <b>LF</b> (linefeed), or <b>CRLF</b> (carriage-return followed by a linefeed)<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, unless it is overridden by an <code>AddTrailingDelimiter=false</code> specification.  
<p>
If an <code>AddTrailingDelimiter=false</code> argument is also specified, no line-end character is added at the end of the serialized subtree. </p>


<li><b>NoEmptyElt</b>
<li><b>NoEmptyElt</b><br>
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. For example:
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>).
<p class="code"> <middleName></middleName> </p>
The default is to serialize an empty element with an empty element tag (as in <code><middleName/></code>).


<li><b>OmitNullElement</b>
<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.  


Line 54: Line 49:
<li><b>WithComments</b><br>  
<li><b>WithComments</b><br>  
Includes in the serialized output all <var>Comment</var> nodes in the specified subtree.  
Includes in the serialized output all <var>Comment</var> nodes in the specified subtree.  
<p>'''Note:''' This option is only a supplement to the <var>ExclCanonical</var> option: specifying <var>WithComments</var> without specifying <var>ExclCanonical</var> has no effect. Specifying <var>ExclCanonical</var> without specifying <var>WithComments</var> causes all <var>Comment</var> nodes to be suppressed from the result.</p>  
<p>'''Note:''' Specifying <var>WithComments</var> without specifying <var>ExclCanonical</var> has no effect. Specifying <var>ExclCanonical</var> without specifying <var>WithComments</var> suppresses all <var>Comment</var> nodes from the result.</p>  


<li><b>XmlDecl</b>
<li><b>XmlDecl</b><br>
Ensures that 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, and if the <var>XmlDoc</var> is not empty.
Ensures that 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,
<var>XmlDecl</var> may only be specified if the top of the subtree being serialized is the <var>Root</var> node.
and if the top of the subtree being serialized is the <var>Root</var> node.</ul>


<tr><th>AddTrailingDelimiter</th>
<tr><th>AddTrailingDelimiter</th>
<td>This Boolean, name required parameter determines whether a final line-end character is added to the serialization when one of the <var>Serial</var> method line-end options (<tt>LF</tt>, <tt>CR</tt>, or <tt>CRLF</tt>) is specified.
<td>This [[Boolean]], [[Methods#Named_parameters|name required]] parameter determines whether a final line-end character is added to the serialization when one of the <var>Serial</var> method line-end options (<var>LF</var>, <var>CR</var>, or <var>CRLF</var>) is specified.


The default value of AddTrailingDelimiter is <tt>True</tt>, so <var>Serial</var> specified with a line-end option adds a trailing line-end by default. If AddTrailingDelimiter is specified as <tt>False</tt>, no final line-end character is added.
The default value of <var>AddTrailingDelimiter</var> is <var>True</var>, so <var>Serial</var> specified with a line-end option adds a trailing line-end by default. If <var>AddTrailingDelimiter</var> is <var>False</var>, no final line-end character is added.
Specifying the AddTrailingDelimiter argument without also specifying one of the line-end options has no effect on the resulting serialization.
Specifying the <var>AddTrailingDelimiter</var> argument without also specifying one of the line-end options has no effect on the resulting serialization.
AddTrailingDelimiter is new as of ''Sirius Mods'' version 7.0. It may be useful if a digital signature must be created which includes line-end characters between XML tags, but the <var>XmlDoc</var> does not contain those line-end Text nodes.</td></tr>
<var>AddTrailingDelimiter</var> is new as of ''Sirius Mods'' version 7.0. It may be useful if a digital signature must be created which includes line-end characters between XML tags, but the <var>XmlDoc</var> does not contain those line-end Text nodes.</td></tr>
</table>
</table>


Line 72: Line 67:
<li>To obtain a <var>Longstring</var> that is the UTF-8
<li>To obtain a <var>Longstring</var> that is the UTF-8
serialization of an entire <var>XmlDoc</var>, including the "XML declaration,"
serialization of an entire <var>XmlDoc</var>, including the "XML declaration,"
use ??[[Xml (XmlDoc function)|Xml]].
use [[Xml (XmlDoc function)|Xml]].
<li>The ''options'' argument values may be specified in any case.
<li>The ''options'' argument values may be specified in any case.
For example,
For example, <code>XmlDecl</code> and <code>xmldecl</code> are interchangeable.
<tt>XmlDecl</tt> and <tt>xmldecl</tt> are interchangeable.
<li>Line-end/whitespace characters:
<li>Line-end/whitespace characters:
<ul>
<ul>
<li>Using one of the line-end character options (CR, LF, CRLF) produces output
<li>Using one of the line-end character options (<var>CR</var>, <var>LF</var>, <var>CRLF</var>) produces output
that is similar to the BothCompact option of the Print method
that is similar to the <var>BothCompact</var> option of the [[Print (XmlDoc/XmlNode subroutine)|Print]] method.
(??[[Print (XmlDoc/XmlNode subroutine)|Print]]).
<li>If one of the line-end
<li>If one of the line-end
(<tt>CR</tt>, <tt>LF</tt>, <tt>CRLF</tt>) options
(<var>CR</var>, <var>LF</var>, <var>CRLF</var>) options
is specified, and an element to be serialized has the
is specified, and an element to be serialized has the
<tt>xml:space="preserve"</tt> attribute, then
<tcode>xml:space="preserve"</code> attribute, then
within the serialization of that element and its descendants, no line-end
within the serialization of that element and its descendants, no line-end characters are inserted.
characters are inserted.


In addition, the <tt>xml:space="default"</tt> attribute has no effect
In addition, the <tt>xml:space="default"</tt> attribute has no effect
Line 95: Line 87:
<li>As of version 6.7, the <var>Serial</var> method uses the hexadecimal
<li>As of version 6.7, the <var>Serial</var> method uses the hexadecimal
character references specified in the XML Canonicalization specification
character references specified in the XML Canonicalization specification
(:hp0 color=SirLink.http://www.w3.org/TR/xml-c14n:ehp0.) to
(http://www.w3.org/TR/xml-c14n) to display the following whitespace characters:
display the following whitespace characters:
<ul>
<ul>
<li>For Attribute nodes: tab, carriage return (CR), and linefeed (LF)
<li>For <var>Attribute</var> nodes: tab, carriage return (CR), and linefeed (LF)
<li>For Text nodes: carriage return
<li>For <var>Text</var> nodes: carriage return
</ul>
</ul>


Since the character references are not subject to the standard XML whitespace
Since the character references are not subject to the standard XML [[XML processing in Janus SOAP#Normalizing whitespace characters|whitespace normalization]],
normalization ([[??]] refid=normwhi.),
a serialized document (or subtree) that is then deserialized will retain this whitespace.
a serialized document (or subtree) that is then deserialized
will retain this whitespace.


These character references are used:
These character references are used:
<dl>
<table class="optionTable">
<dt>tab
<tr><td>'''tab'''<td>&amp;#x9;</tr>
<dd>&amp;#x9;
<tr><td>'''CR'''<td>&amp;#xD;</tr>
<dt>CR
<tr><td>'''LF'''<td>&amp;#xA;</tr>
<dd>&amp;#xD;
</table>
<dt>LF
<dd>&amp;#xA;
</dl>


The EBCDIC and corresponding ASCII encodings of the characters is:
The EBCDIC and corresponding ASCII encodings of the characters is:
Line 125: Line 111:
</table>
</table>
</ul>
</ul>
<li>As of ''Sirius Mods'' version 7.6, Attribute values are always serialized
<li>As of ''Sirius Mods'' version 7.6, <var>Attribute</var> values are always serialized
within double-quotation-mark (<tt>"</tt>) delimiters,
within double-quotation-mark (<tt>"</tt>) delimiters,
and a double-quotation mark character in an attribute value is serialized
and a double-quotation mark character in an attribute value is serialized
as <tt>&amp;quot;</tt>.
as <code>&amp;quot;</code>.
Prior to version 7.6, this convention was not strictly observed.
Prior to version 7.6, this convention was not strictly observed.
</ul>
</ul>
Line 136: Line 122:
<li>In the following example, the <var>Serial</var> method EBCDIC
<li>In the following example, the <var>Serial</var> method EBCDIC
formatting of a document is shown.
formatting of a document is shown.
A Print statement display of the default UTF-8 formatting of <var>Serial</var> is a
A <var>Print</var> statement display of the default UTF-8 formatting of <var>Serial</var> is a
string that is not readily decipherable.
string that is not readily decipherable.
<p class="code">Begin
<p class="code">Begin
Line 162: Line 148:


The example results follow:
The example results follow:
<p class="code">Serial method output follows:
<p class="output">Serial method output follows:
<nowiki><top><a><b>05</b></a><c><d att="val"/></c></top></nowiki>
<nowiki><top><a><b>05</b></a><c><d att="val"/></c></top></nowiki>
</p>
</p>
Line 169: Line 155:
==Request-Cancellation Errors==
==Request-Cancellation Errors==
<ul>
<ul>
<li><i>XPath</i> is invalid.
<li><var>XPath</var> is invalid.
<li>Result of <i>XPath</i> is empty.
<li>Result of <var>XPath</var> is empty.
<li><i>Options</i> are 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>
Line 181: Line 167:
<ul>
<ul>
<li>The subroutine that serializes an <var>XmlDoc</var> and sends it as a
<li>The subroutine that serializes an <var>XmlDoc</var> and sends it as a
Web response is ??[[WebSend (XmlDoc subroutine)|WebSend]], described below.
Web response is [[WebSend (XmlDoc subroutine)|WebSend]].
<li>Additional serializing methods include:
<li>Additional serializing methods include:
<ul>
<ul>
<li>[[Xml (XmlDoc function)|Xml]]
<li>[[Xml (XmlDoc function)|Xml]]
<li>[[Print (XmlDoc/XmlNode subroutine)|Print]]
<li>[[Print (XmlDoc/XmlNode subroutine)|Print]]
<li>AddXml (HttpRequest class, described in the [[Janus Sockets]]R.)
<li>[[AddXml]] method of the [[HttpRequest]] class
</ul>
</ul>
<li>To deserialize a string,
<li>To deserialize a string,
use ??[[LoadXml (XmlDoc/XmlNode function)|LoadXml]]
use [[LoadXml (XmlDoc/XmlNode function)|LoadXml]]
or ??[[WebReceive (XmlDoc function)|WebReceive]].
or [[WebReceive (XmlDoc function)|WebReceive]].
<li>For more information about using XPath expressions, see [[XPath]].
<li>For more information about using XPath expressions, see [[XPath]].
</ul>
</ul>

Revision as of 21:34, 14 February 2011

Serialize selected subtree as string (XmlDoc and XmlNode classes)


This function converts an XmlDoc subtree to the UTF-8 or EBCDIC text string representation of the subtree. (This process is called serialization, because the text representation of a document is called the serial form.)

Syntax

%string = nr:Serial[( [xpath], [options], [AddTrailingDelimiter= boolean])] Throws XPathError

Syntax terms

%utfOrEbcd A string variable for the string serialization of the subtree, encoded either in UTF-8 or, if the EBCDIC option (see below) is used, in EBCDIC.
nr An XmlDoc or XmlNode, used as the context node for the xpath expression. If an XmlDoc, the Root node is the context node.
xpath A Unicode string that is an XPath expression that results in a nodelist, the head of which is the top of the subtree to serialize. This is an optional argument; its default is a period (.), that is, the node referenced by the method object (nr). Prior to Sirius Mods version 7.6, this is an EBCDIC string.
options A blank delimited string that can contain one or more of the following options, which are identified below and described in greater detail in "XmlDoc API serialization options":
  • EBCDIC
    Produces serialized output in EBCDIC text rather than the default encoding, UTF-8.
  • ExclCanonical
    Produces serialized output in exclusive XML canonical form, as defined in the W3C "Exclusive XML Canonicalization" specification (http://www.w3.org/tr/xml-exc-c14n).
  • 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 must also specify CR, LF, or CRLF (see below).
  • CR (carriage-return), LF (linefeed), or CRLF (carriage-return followed by a linefeed)
    Inserts one of these line-end options to provide line breaks in the serialized output, unless it is overridden by an AddTrailingDelimiter=false specification.
  • 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.
  • WithComments
    Includes in the serialized output all Comment nodes in the specified subtree.

    Note: Specifying WithComments without specifying ExclCanonical has no effect. Specifying ExclCanonical without specifying WithComments suppresses all Comment nodes from the result.

  • XmlDecl
    Ensures that 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 top of the subtree being serialized is the Root node.
AddTrailingDelimiter This Boolean, name required parameter determines whether a final line-end character is added to the serialization when one of the Serial method line-end options (LF, CR, or CRLF) is specified.

The default value of AddTrailingDelimiter is True, so Serial specified with a line-end option adds a trailing line-end by default. If AddTrailingDelimiter is False, no final line-end character is added. Specifying the AddTrailingDelimiter argument without also specifying one of the line-end options has no effect on the resulting serialization.

AddTrailingDelimiter is new as of Sirius Mods version 7.0. It may be useful if a digital signature must be created which includes line-end characters between XML tags, but the XmlDoc does not contain those line-end Text nodes.

Usage notes

  • To obtain a Longstring that is the UTF-8 serialization of an entire XmlDoc, including the "XML declaration," use Xml.
  • The options argument values may be specified in any case. For example, XmlDecl and xmldecl are interchangeable.
  • Line-end/whitespace characters:
    • Using one of the line-end character options (CR, LF, CRLF) produces output that is similar to the BothCompact option of the Print method.
    • If one of the line-end (CR, LF, CRLF) options is specified, and an element to be serialized has the <tcode>xml:space="preserve" attribute, then within the serialization of that element and its descendants, no line-end characters are inserted. In addition, the xml: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 containing xml:space="preserve".
    • As of version 6.7, the Serial method uses the hexadecimal character references specified in the XML Canonicalization specification (http://www.w3.org/TR/xml-c14n) to display the following whitespace characters:
      • For Attribute nodes: tab, carriage return (CR), and linefeed (LF)
      • For Text nodes: carriage return

      Since the character references are not subject to the standard XML whitespace normalization, a serialized document (or subtree) that is then deserialized will retain this whitespace.

      These character references are used:

      tab&#x9;
      CR&#xD;
      LF&#xA;

      The EBCDIC and corresponding ASCII encodings of the characters is:

      EBCDICASCII
      tabX'05'X'09'
      CRX'0D'X'0D'
      LFX'25'X'0A'
  • 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.

Examples

  1. In the following example, the Serial method EBCDIC formatting of a document is shown. A Print statement display of the default UTF-8 formatting of Serial is a string that is not readily decipherable.

    Begin %doc is Object XmlDoc %sl is Object Stringlist %doc = New %sl = New text to %sl <top> <a> <b>05</b> </a> <c> <d att="val"/> </c> </top> end text Call %doc:LoadXml(%sl) Print 'Serial method output follows:' Print %doc:Serial('top', 'ebcdic') End

    The example results follow:

    Serial method output follows: <top><a><b>05</b></a><c><d att="val"/></c></top>

Request-Cancellation Errors

  • XPath is invalid.
  • Result of XPath is empty.
  • An options setting is invalid.
  • Insufficient free space exists in CCATEMP.


See also

  • The subroutine that serializes an XmlDoc and sends it as a Web response is WebSend.
  • Additional serializing methods include:
  • To deserialize a string, use LoadXml or WebReceive.
  • For more information about using XPath expressions, see XPath.