Xml (XmlDoc function): Difference between revisions
Jump to navigation
Jump to search
m (→Syntax terms) |
mNo edit summary |
||
Line 16: | Line 16: | ||
<ul> | <ul> | ||
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br> | <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, | Whether or not 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 node selected by <var class="term">xpath</var> is the <var>Root</var> node. <var>AllowXmlDecl</var> is the default. | and if the node selected by <var class="term">xpath</var> is the <var>Root</var> node. <var>AllowXmlDecl</var> is the default. | ||
Line 34: | Line 34: | ||
This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). | This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering). | ||
It is superseded by the [[Serial (XmlDoc/XmlNode function)|Serial]] method <var>ExclCanonical</var> option. | It is superseded by the <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> method <var>ExclCanonical</var> option. | ||
</ul></td></tr> | </ul></td></tr> | ||
</table> | </table> | ||
Line 52: | Line 52: | ||
The [[#See also|"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>XmlDoc</var>. | an EBCDIC serialization of an <var>XmlDoc</var>. | ||
<li>You can use the [[Print (XmlDoc/XmlNode subroutine)|Print]] | <li>You can use the <var>[[Print (XmlDoc/XmlNode subroutine)|Print]]</var> | ||
method to display a document on the terminal, | method to display a document on the terminal, | ||
or to ''capture'' a displayable version of a document, but <var>Print</var> is | or to ''capture'' a displayable version of a document, but <var>Print</var> is | ||
Line 67: | Line 67: | ||
==Examples== | ==Examples== | ||
<ul> | <ul> | ||
<li>The [[AddXml]] method of the [[HttpRequest]] class | <li>The <var>[[AddXml]]</var> method of the <var>[[HttpRequest]]</var> class | ||
has nearly the same options as the <var>Xml</var> function. | has nearly the same options as the <var>Xml</var> function. | ||
The following fragment serializes an <var>XmlDoc</var> and sends it | The following fragment serializes an <var>XmlDoc</var> and sends it | ||
as a request to a web server. | 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 <var>[[$Sock_Send]]</var> directly, | ||
instead of using an [[HTTP Helper]] object, always use | instead of using an <var>[[HTTP Helper]]</var> object, always use | ||
the >var>BINARY</var> option of <var>$Sock_Send</var>, because the | the >var>BINARY</var> option of <var>$Sock_Send</var>, because the | ||
result of the <var>Xml</var> function is UTF-8, rather than EBCDIC. | result of the <var>Xml</var> function is UTF-8, rather than EBCDIC. | ||
Line 107: | Line 107: | ||
<ul> | <ul> | ||
<li>Use [[Print (XmlDoc/XmlNode subroutine)|Print]] to display an XML document for debugging. | <li>Use <var>[[Print (XmlDoc/XmlNode subroutine)|Print]]</var> to display an XML document for debugging. | ||
<li>Use [[Serial (XmlDoc/XmlNode function)|Serial]] with the EBCDIC option to obtain an EBCDIC serialization of | <li>Use <var>[[Serial (XmlDoc/XmlNode function)|Serial]]</var> with the EBCDIC option to obtain an EBCDIC serialization of | ||
an XML document. | an XML document. | ||
<li>Use [[WebSend (XmlDoc subroutine)|WebSend]] | <li>Use <var>[[WebSend (XmlDoc subroutine)|WebSend]]</var> | ||
to serialize an <var>XmlDoc</var> and send it as an HTTP response using [[Janus Web Server]]. | to serialize an <var>XmlDoc</var> and send it as an HTTP response using [[Janus Web Server]]. | ||
<li>The string deserialization functions are [[LoadXml (XmlDoc/XmlNode function)|LoadXml]] | <li>The string deserialization functions are [[LoadXml (XmlDoc/XmlNode function)|LoadXml]] | ||
and [[WebReceive (XmlDoc function)|WebReceive]]. | and <var>[[WebReceive (XmlDoc function)|WebReceive]]</var>. | ||
</ul> | </ul> |
Revision as of 15:50, 17 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
%string | 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.