Serial (XmlDoc/XmlNode function): Difference between revisions
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 < | <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 < | <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> | <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 (< | <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 | <li><b>Indent <i>n</i></b><br> | ||
Inserts space characters | 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><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. | ||
<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. | 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>). | ||
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:''' | <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, | 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, | ||
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 (< | <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 < | 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 | 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. | ||
< | |||
<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 | that is similar to the <var>BothCompact</var> option of the [[Print (XmlDoc/XmlNode subroutine)|Print]] method. | ||
<li>If one of the line-end | <li>If one of the line-end | ||
(< | (<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 | ||
< | <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 | ||
( | (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 | 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: | ||
< | <table class="optionTable"> | ||
< | <tr><td>'''tab'''<td>&#x9;</tr> | ||
< | <tr><td>'''CR'''<td>&#xD;</tr> | ||
< | <tr><td>'''LF'''<td>&#xA;</tr> | ||
< | </table> | ||
< | |||
< | |||
</ | |||
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 < | as <code>&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=" | <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>< | <li><var>XPath</var> is invalid. | ||
<li>Result of < | <li>Result of <var>XPath</var> is empty. | ||
<li>< | <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 | 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 | <li>[[AddXml]] method of the [[HttpRequest]] class | ||
</ul> | </ul> | ||
<li>To deserialize a string, | <li>To deserialize a string, | ||
use | use [[LoadXml (XmlDoc/XmlNode function)|LoadXml]] | ||
or | 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":
|
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
andxmldecl
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 	 CR 
 LF 
 The EBCDIC and corresponding ASCII encodings of the characters is:
EBCDIC ASCII tab X'05' X'09' CR X'0D' X'0D' LF X'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
"
. Prior to version 7.6, this convention was not strictly observed.
Examples
- 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:
- Xml
- AddXml method of the HttpRequest class
- To deserialize a string, use LoadXml or WebReceive.
- For more information about using XPath expressions, see XPath.