Serial (XmlDoc/XmlNode function): Difference between revisions
m (→Examples) |
m (→See also) |
||
Line 124: | Line 124: | ||
<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]]. | Web response is <var>[[WebSend (XmlDoc subroutine)|WebSend]]</var>. | ||
<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]]</var> (<var>[[HttpRequest]]</var> class) | ||
</ul> | </ul> | ||
<li>To deserialize a string, | <li>To deserialize a string, | ||
use [[LoadXml (XmlDoc/XmlNode function)|LoadXml]] | use <var>[[LoadXml (XmlDoc/XmlNode function)|LoadXml]]</var> | ||
or [[WebReceive (XmlDoc function)|WebReceive]]. | or <var>[[WebReceive (XmlDoc function)|WebReceive]]</var>. | ||
<li>For more information about using XPath expressions, see [[XPath|"XPath"]]. | <li>For more information about using XPath expressions, see [[XPath|"XPath"]]. | ||
</ul> | </ul> |
Revision as of 21:15, 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
- 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. - 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".