Serial (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (xpath arg)
 
(28 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:XmlDoc/XmlNode:Serial subtitle}}
{{Template:XmlDoc/XmlNode:Serial subtitle}}
<var>Serial</var> converts an <var>XmlDoc</var> 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.


This function converts an <var>XmlDoc</var> 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==
==Syntax==
{{Template:XmlDoc/XmlNode:Serial syntax}}
{{Template:XmlDoc/XmlNode:Serial syntax}}
Line 11: Line 7:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%string</th>
<tr><th>%string</th>
<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>
<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 <var class="term">xpath</var> expression. If an <var>XmlDoc</var>, the <var>Root</var> 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 [[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>).
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|Xpath expression]] that results in a nodelist, the head of which is the top of the subtree to serialize. Any other nodes in the nodelist are ignored.
<p>
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>). </p>
<p>
Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr>


Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
<tr><th><div id="options"></div>options</th>
<td>A blank delimited string that can contain one or more of the following options (but no repeats).
<p class="note">'''Note:''' These options are described in greater detail in [[XmlDoc API serialization options]]. </p>
<ul>
<li><b>CharacterEncodeAll</b><br>
If the <var>EBCDIC</var> option is specified, use character encoding in all contexts (that is, not only in <var>Attribute</var> or <var>Element</var> values) to display Unicode characters that do not translate to EBCDIC. This option is available starting with version 8.0 of the <var class="product">Sirius Mods</var>.


<tr><th>options</th>
<li><b>EBCDIC</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"]]:
<br>Produces serialized output in EBCDIC text rather than the default encoding, UTF-8.  
<ul>
<li><b>EBCDIC</b><br>
Produces serialized output in EBCDIC text rather than the default encoding, UTF-8.  


<li><b>ExclCanonical</b><br>
<li><b>ExclCanonical</b>
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).  
<br>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 <i>n</i></b><br>
<li><b>Indent <i>n</i></b>
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).
<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 must also specify <code>CR</code>, <code>LF</code>, or <code>CRLF</code> (see below). </li>


<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)
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.
<br>Inserts one of these line-end characters to provide line breaks in the serialized output. </li>


<li><b>NoEmptyElt</b><br>
<div id="noempty"></div>
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>).
<li><b>NoEmptyElt</b>
<br>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>).  
<p>
<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>


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


<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>ExclCanonical</var> option. </li>


This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering).
<li><b>UTF-8</b>
It is superseded by the <var>ExclCanonical</var> option.
<br>Produces serialized output in UTF-8. This is the default. </li>


<li><b>WithComments</b><br>  
<li><b>WithComments</b>
Includes in the serialized output all <var>Comment</var> nodes in the specified subtree.  
<br>Includes in the serialized output all <var>Comment</var> nodes in the specified subtree.
<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>  
<p class="note">'''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>


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


<tr><th>AddTrailingDelimiter</th>
<tr><th><var>AddTrailingDelimiter</var></th>
<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.
<td>This [[Methods#Named parameters|name required]] parameter is a <var>[[Enumerations#Using Boolean enumerations|Boolean]]</var> value, which 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.
 
<p>
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.
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.</p>
Specifying the <var>AddTrailingDelimiter</var> argument without also specifying one of the line-end options has no effect on the resulting serialization.
<p>
<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>
Specifying the <var>AddTrailingDelimiter</var> argument without also specifying one of the line-end options has no effect on the resulting serialization.</p>
<p>
<var>AddTrailingDelimiter</var> was introduced as of <var class="product">Sirius Mods</var> 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 <var>Text</var> nodes.</p></td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>To obtain a <var>Longstring</var> that is the UTF-8
<li>The <var class="term">options</var> argument values may be specified in any case. For example, <code>XmlDecl</code> and <code>xmldecl</code> are interchangeable.
serialization of an entire <var>XmlDoc</var>, including the "XML declaration,"
<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.
use [[Xml (XmlDoc function)|Xml]].
<li>The ''options'' argument values may be specified in any case.
For example, <code>XmlDecl</code> and <code>xmldecl</code> are interchangeable.
 
<li>As of ''Sirius Mods'' 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 attribute value is serialized
as <code>&amp;quot;</code>.
Prior to version 7.6, this convention was not strictly observed.
</ul>
</ul>


==Examples==
==Examples==
<ol>
<ol>
<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. A <var>Print</var> statement display of the default UTF-8 formatting of <var>Serial</var> is a string that is not readily decipherable.
formatting of a document is shown.
<p class="code">begin
A <var>Print</var> statement display of the default UTF-8 formatting of <var>Serial</var> is a
  %doc is object xmlDoc
string that is not readily decipherable.
  %sl is object [[Stringlist_class|stringlist]]
<p class="code">Begin
  %doc = new
%doc is Object XmlDoc
  %sl = new
%sl is Object Stringlist
%doc = New
%sl = New


text to %sl
  text to %sl
<nowiki><top>
  <nowiki><top>
  <a>
      <a>
      <b>05</b>
        <b>05</b>
  </a>
      </a>
  <c>
      <c>
      <d att="val"/>
        <d att="val"/>
  </c>
      </c>
</top></nowiki>
  </top></nowiki>
end text
  end text
 
 
Call %doc:LoadXml(%sl)
  [[Notation_conventions_for_methods#Callable_methods|Call]] %doc:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]](%sl)
Print 'Serial method output follows:'
  print 'Serial method output follows:'
Print %doc:Serial('top', 'ebcdic')
  print %doc:serial('top', 'ebcdic')
End
end
</p>
</p>
The example results follow:
The example results follow:
<p class="output">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>
<li>In the following fragment, the <var>Serial</var> method EBCDIC formatting of a document with untranslatable Unicode is shown.
<p class="code">%doc2:[[AddElement_(XmlDoc/XmlNode_function)|addElement]]('circumference', -
  '2 * &amp;#x3C0; * r':U)
print %doc2:serial(, 'ebcdic')
</p>
The result follows (the Unicode codepoint for the Greek letter &#x03c0; has the hexadecimal value 03C0):
<p class="output"><circumference>2 * &amp;#x03C0; * r</circumference>
</p>
</p>
</ol>
</ol>


==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 class="term">xpath</var> is invalid.
<li><var class="term">xpath</var> argument is invalid.
<li>Result of <var class="term">xpath</var> is empty.
<li>Result of <var class="term">xpath</var> is empty.
<li>An <var class="term">options</var> setting is invalid.
<li>An <var class="term">options</var> setting is invalid.
Line 122: Line 127:


==See also==
==See also==
{{Template:XmlDoc/XmlNode:Serial footer}}
<ul>
<li>The subroutine that serializes an <var>XmlDoc</var> and sends it as a Web response is <var>[[WebSend (XmlDoc subroutine)|WebSend]]</var>. </li>


<ul>
<li>The subroutine that serializes an <var>XmlDoc</var> and sends it as a
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><var>[[Xml (XmlDoc function)|Xml]]</var>
<li>[[Print (XmlDoc/XmlNode subroutine)|Print]]
<li><var>[[Print (XmlDoc/XmlNode subroutine)|Print]]</var>
<li>[[AddXml]] ([[HttpRequest]] class)
<li><var>[[AddXml (HttpRequest subroutine)|AddXml]]</var> (<var>[[HttpRequest class|HttpRequest]]</var> class)
</ul>
</ul> </li>
<li>To deserialize a string,
 
use [[LoadXml (XmlDoc/XmlNode function)|LoadXml]]
<li>See the description of [[XmlDoc_API_serialization_options#EBCDIC_serialization_of_untranslatable_Unicode_characters|Unicode to EBCDIC conversion]] performed by <var>Serial</var> with the <code>EBCDIC</code> option. </li>
or [[WebReceive (XmlDoc function)|WebReceive]].
 
<li>For more information about using XPath expressions, see [[XPath|"XPath"]].
<li>To deserialize a string, use <var>[[LoadXml (XmlDoc/XmlNode function)|LoadXml]]</var> or <var>[[WebReceive (XmlDoc function)|WebReceive]]</var>. </li>
 
<li>For more information about using XPath expressions, see [[XPath]]. </li>
 
<li>For additional discussion about serialization, see [[XmlDoc API#Transport: receiving and sending XML|Transport: receiving and sending XML]].</li>
</ul>
</ul>
{{Template:XmlDoc/XmlNode:Serial footer}}

Latest revision as of 17:58, 18 February 2015

Serialize selected subtree as string (XmlDoc and XmlNode classes)

Serial 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

%string 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. Any other nodes in the nodelist are ignored.

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 (but no repeats).

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

  • CharacterEncodeAll
    If the EBCDIC option is specified, use character encoding in all contexts (that is, not only in Attribute or Element values) to display Unicode characters that do not translate to EBCDIC. This option is available starting with version 8.0 of the Sirius Mods.
  • 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 characters 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 ExclCanonical option.
  • UTF-8
    Produces serialized output in UTF-8. This is the default.
  • 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 name required parameter is a Boolean value, which 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 was introduced 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

  • The options argument values may be specified in any case. For example, XmlDecl and xmldecl are interchangeable.
  • 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

  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>

  2. In the following fragment, the Serial method EBCDIC formatting of a document with untranslatable Unicode is shown.

    %doc2:addElement('circumference', - '2 * &#x3C0; * r':U) print %doc2:serial(, 'ebcdic')

    The result follows (the Unicode codepoint for the Greek letter π has the hexadecimal value 03C0):

    <circumference>2 * &#x03C0; * r</circumference>

Request-cancellation errors

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

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

See also