Xml (XmlDoc function): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 46: | Line 46: | ||
==Examples== | ==Examples== | ||
<ol> | <ol> | ||
<li>The <var>[[AddXml]]</var> method of the <var>[[HttpRequest]]</var> 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 web server. | <li>The <var>[[AddXml (HttpRequest subroutine)|AddXml]]</var> method of the <var>[[HttpRequest class|HTtpRequest]]</var> 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 web server. | ||
<p>Note that if you use the <var>Xml</var> function and <var>[[$Sock_Send]]</var> directly, instead of using an <var>[[HTTP Helper]]</var> object, always use 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.</p> | <p>Note that if you use the <var>Xml</var> function and <var>[[$Sock_Send]]</var> directly, instead of using an <var>[[HTTP Helper]]</var> object, always use 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.</p> | ||
<p class="code"> %httpreq object httpRequest | <p class="code"> %httpreq object httpRequest | ||
Line 56: | Line 56: | ||
<dateRange/></inquire>', 'NoEmptyElt') | <dateRange/></inquire>', 'NoEmptyElt') | ||
%httpreq:[[URL]] = 'foo.com/bar' | %httpreq:[[URL (HttpRequest property)|URL]] = 'foo.com/bar' | ||
%httpreq:[[addXml]](%doc) | %httpreq:[[AddXml (HttpRequest subroutine)|addXml]](%doc) | ||
%httpresp = %httpreq:[[post]]('HTTP_CLIENT') | %httpresp = %httpreq:[[Post (HttpRequest function)|post]]('HTTP_CLIENT') | ||
</p> | </p> | ||
<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: | <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: |
Revision as of 22:22, 21 June 2011
Serialize XmlDoc as UTF-8 string (XmlDoc class)
The Xml 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 to be 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 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
- doc object 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.