Serial (XmlDoc/XmlNode function): Difference between revisions
m (→See also) |
mNo edit summary |
||
Line 31: | Line 31: | ||
<li><b>Indent <i>n</i></b><br> | <li><b>Indent <i>n</i></b><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 < | 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 <var>CR</var>, <var>LF</var>, or <var>CRLF</var> (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> | ||
Line 52: | Line 52: | ||
<li><b>XmlDecl</b><br> | <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, 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 <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.</ul></td></tr> | and if the top of the subtree being serialized is the <var>Root</var> node.</ul></td></tr> | ||
<tr><th>AddTrailingDelimiter</th> | <tr><th>AddTrailingDelimiter</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 <var>[[Boolean]]</var>, [[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 <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. | ||
Specifying the <var>AddTrailingDelimiter</var> 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. | ||
<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> | <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 <var>Text</var> nodes.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>The ''options'' argument values may be specified in any case. | <li>The ''options'' argument values may be specified in any case. | ||
For example, <code>XmlDecl</code> and <code>xmldecl</code> are interchangeable. | For example, <code>XmlDecl</code> and <code>xmldecl</code> are interchangeable. | ||
<li>As of | <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, | within double-quotation-mark (<tt>"</tt>) delimiters, | ||
and a double-quotation mark character in an | and a double-quotation mark character in an <var>Attribute</var> value is serialized | ||
as <code>&quot;</code>. | 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. |
Revision as of 21:41, 16 March 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
%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. 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), 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
- The options argument values may be specified in any case.
For example,
XmlDecl
andxmldecl
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
"
. 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 (HttpRequest class)
- To deserialize a string, use LoadXml or WebReceive.
- For more information about using XPath expressions, see "XPath".