Xml (XmlDoc function): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 3: | Line 3: | ||
This function converts an <var>Xml</var>Doc to its textually represented XML document | This function converts an <var>Xml</var>Doc to its textually represented XML document | ||
(this process is called '''serialization''', | (this process is called '''serialization''', | ||
because the text representation of a document is called the '''serial''' | because the text representation of a document is called the '''serial''' form). | ||
form). | |||
==Syntax== | ==Syntax== | ||
{{Template:XmlDoc:Xml syntax}} | {{Template:XmlDoc:Xml syntax}} | ||
Line 14: | Line 13: | ||
<td><var>Xml</var>Doc expression, whose content is serialized. </td></tr> | <td><var>Xml</var>Doc expression, whose content is serialized. </td></tr> | ||
<tr><th>options</th> | <tr><th>options</th> | ||
<td> | <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"]]: | ||
<ul> | |||
Inserts space characters | <li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br> | ||
Whether or not 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 node selected by <var class="term">xpath</var> is the <var>Root</var> node. <var>AllowXmlDecl</var> is the default. | |||
<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 <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> | |||
Inserts one of these line-end options to provide line breaks in the serialized output. | |||
<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. The default is to serialize an empty element with an empty element tag (as in <code><middleName/></code>). | |||
<li><b>OmitNullElement</b><br> | |||
An Element node that has no children and no Attributes will not be serialized, unless it is the top level | 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><b>SortCanonical</b><br> | |||
This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). | |||
This | It is superseded by the [[Serial (XmlDoc/XmlNode function)|Serial]] method <var>ExclCanonical</var> option. | ||
</ul></td></tr> | |||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>Options may be specified in any case, for example, you can use | <li>Options may be specified in any case, for example, you can use | ||
either < | either <code>NoXmlDecl</code> or <code>noxmldecl</code>, interchangeably. | ||
<li>The | <li>The <var>Xml</var>Doc method object must be well-formed (that is, | ||
it must contain an Element node). | it must contain an <var>Element</var> node). | ||
For more information | For more information, see | ||
[[XML processing in Janus SOAP#Well-formed documents and validation|"Well-formed documents and validation"]]. | |||
<li>Since the result of the <var>Xml</var> function has UTF-8 encoding, you | <li>Since the result of the <var>Xml</var> function has UTF-8 encoding, you | ||
cannot treat it as an EBCDIC string: for example, printing the string | cannot treat it as an EBCDIC string: for example, printing the string | ||
will not produce displayable characters. | will not produce displayable characters. | ||
The "See Also" section below mentions some methods for obtaining | The [[#See also|"See Also"]] section below mentions some methods for obtaining | ||
an EBCDIC serialization of an <var> | an EBCDIC serialization of an <var>XmlDoc</var>. | ||
<li>You can use the | <li>You can use the [[Print (XmlDoc/XmlNode subroutine)|Print]] | ||
method to display a document on the terminal, | |||
to display a document on the terminal, | or to ''capture'' a displayable version of a document, but <var>Print</var> is | ||
or to | |||
used to insert line breaks and optional indentation, which may not be an | used to insert line breaks and optional indentation, which may not be an | ||
accurate serialization of an <var> | accurate serialization of an <var>XmlDoc</var>. | ||
<li>As of ''Sirius Mods'' version 7.6, <var>Attribute</var> values are always serialized | |||
<li>As of ''Sirius Mods'' version 7.6, | |||
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. | ||
Line 117: | Line 67: | ||
==Examples== | ==Examples== | ||
<ul> | <ul> | ||
<li>The [[ | <li>The [[AddXml]] method of the [[HttpRequest]] class | ||
has nearly the same options as the <var>Xml</var> function. | |||
The following fragment serializes an <var>XmlDoc</var> and sends it | |||
as a request to a | as a request to a web server. | ||
Note that if you use the <var>Xml</var> function and $Sock_Send directly, | Note that if you use the <var>Xml</var> function and [[$Sock_Send]] directly, | ||
instead of using an HTTP | instead of using an [[HTTP Helper]] object, always use | ||
the BINARY option of $Sock_Send, because the | the >var>BINARY</var> option of <var>$Sock_Send</var>, because the | ||
result of the | result of the <var>Xml</var> function is UTF-8, rather than EBCDIC. | ||
<var>Xml</var> function is UTF-8, rather than EBCDIC. | <p class="code"> %httpreq object HttpRequest | ||
<p class="code">%httpreq object HttpRequest | %httpresp object HttpResponse | ||
%httpresp object HttpResponse | %doc object XmlDoc | ||
%doc object XmlDoc | %httpreq = New | ||
%httpreq = New | %doc = New | ||
%doc = New | %doc:LoadXml('<inquire><stock>IBM</stock>' With - | ||
%doc:LoadXml('<inquire><stock>IBM</stock>' With - | <dateRange/></inquire>', 'NoEmptyElt') | ||
%httpreq:URL = 'foo.com/bar' | %httpreq:URL = 'foo.com/bar' | ||
%httpreq:AddXml(%doc) | %httpreq:AddXml(%doc) | ||
%httpresp = %httpreq:Post('HTTP_CLIENT') | %httpresp = %httpreq:Post('HTTP_CLIENT') | ||
</p> | </p> | ||
<li>The following fragment is a simple example for serializing an <var> | <li>The following fragment is a simple example for serializing an <var>XmlDoc</var>, which | ||
could then, for example, be sent on a transport such as MQ: | could then, for example, be sent on a transport such as MQ: | ||
<p class="code">%s Longstring | <p class="code"> %s Longstring | ||
%s = %doc:Xml | %s = %doc:Xml | ||
</p> | </p> | ||
</ul> | </ul> | ||
===Request- | ===Request-cancellation errors=== | ||
<ul> | <ul> | ||
<li><var>XmlDoc</var> does not contain an Element. | <li><var>XmlDoc</var> does not contain an <var>Element</var>. | ||
<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 158: | Line 107: | ||
<ul> | <ul> | ||
<li>Use | <li>Use [[Print (XmlDoc/XmlNode subroutine)|Print]] to display an XML document for debugging. | ||
<li>Use | <li>Use [[Serial (XmlDoc/XmlNode function)|Serial]] with the EBCDIC option to obtain an EBCDIC serialization of | ||
an XML document. | an XML document. | ||
<li>Use | <li>Use [[WebSend (XmlDoc subroutine)|WebSend]] | ||
to serialize an <var> | to serialize an <var>XmlDoc</var> and send it as an HTTP response using [[Janus Web Server]]. | ||
<li>The string deserialization functions are | <li>The string deserialization functions are [[LoadXml (XmlDoc/XmlNode function)|LoadXml]] | ||
and | and [[WebReceive (XmlDoc function)|WebReceive]]. | ||
</ul> | </ul> |
Revision as of 03:20, 16 February 2011
Serialize XmlDoc as UTF-8 string (XmlDoc class)
This function converts an XmlDoc to its textually represented XML document
(this process is called serialization,
because the text representation of a document is called the serial form).
Syntax
%string = doc:Xml[( [options])]
Syntax terms
utf8Str | The string serialization of the XmlDoc, encoded in UTF-8. |
---|---|
doc | XmlDoc expression, whose content is serialized. |
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":
|
Usage notes
- Options may be specified in any case, for example, you can use
either
NoXmlDecl
ornoxmldecl
, interchangeably. - The XmlDoc method object must be well-formed (that is, it must contain an Element node). For more information, see "Well-formed documents and validation".
- Since the result of the Xml function has UTF-8 encoding, you cannot treat it as an EBCDIC string: for example, printing the string will not produce displayable characters. The "See Also" section below mentions some methods for obtaining an EBCDIC serialization of an XmlDoc.
- You can use the Print method to display a document on the terminal, or to capture a displayable version of a document, but Print is used to insert line breaks and optional indentation, which may not be an accurate serialization of an XmlDoc.
- 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
- The AddXml method of the HttpRequest class
has nearly the same options as the Xml function.
The following fragment serializes an XmlDoc and sends it
as a request to a web server.
Note that if you use the Xml function and $Sock_Send directly,
instead of using an HTTP Helper object, always use
the >var>BINARY option of $Sock_Send, because the
result of the Xml function is UTF-8, rather than EBCDIC.
%httpreq object HttpRequest %httpresp object HttpResponse %doc object XmlDoc %httpreq = New %doc = New %doc:LoadXml('<inquire><stock>IBM</stock>' With - <dateRange/></inquire>', 'NoEmptyElt') %httpreq:URL = 'foo.com/bar' %httpreq:AddXml(%doc) %httpresp = %httpreq:Post('HTTP_CLIENT')
- The following fragment is a simple example for serializing an XmlDoc, which
could then, for example, be sent on a transport such as MQ:
%s Longstring %s = %doc:Xml
Request-cancellation errors
- XmlDoc does not contain an Element.
- An options setting is invalid.
- Insufficient free space exists in CCATEMP.
See also
- Use Print to display an XML document for debugging.
- Use Serial with the EBCDIC option to obtain an EBCDIC serialization of an XML document.
- Use WebSend to serialize an XmlDoc and send it as an HTTP response using Janus Web Server.
- The string deserialization functions are LoadXml and WebReceive.