Xml (XmlDoc function): Difference between revisions
m (1 revision) |
m (1 revision) |
(No difference)
|
Revision as of 17:14, 25 January 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 | Any combination of the following options (but single occurrences only):
|
Usage notes
- Options may be specified in any case, for example, you can use either NoXmlDecl or noxmldecl, interchangeably.
- The XmlDoc method object must be well-formed (that is, it must contain an Element node). For more information about well-formed documents, see ?? refid=welform..
- 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 (??Print) 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.
- Using one of the line-end character options (CR, LF, CRLF) produces output that is analogous to the BothCompact option of the Print method.
- If one of the line-end (CR, LF, CRLF) options or if Indent is specified, and an element to be serialized has the xml:space="preserve" attribute, then within the serialization of that element and its descendants, no line-end (nor indentation) characters are inserted to provide readability. In addition, the xml:space="default" attribute has no effect under these options: specified by itself, it does not influence serialization, nor does it cause resumption of readability line-ends or indents if they were suspended by a containing xml:space="preserve".
- As of version 6.7, the Xml method uses the hexadecimal
character references specified in the XML Canonicalization specification
(:hp0 color=SirLink.http://www.w3.org/TR/xml-c14n:ehp0.) to
display the following characters:
- For Attribute nodes: tab, carriage return, and linefeed
- For Text nodes: carriage return
Since the character references are not subject to the standard XML whitespace normalization (?? refid=normwhi.), a serialized document (or subtree) that is then deserialized will retain this whitespace.
These character references are used:
- tab
- 	
- CR
- 
- LF
- 

The EBCDIC and corresponding ASCII encodings of the characters is:
- &thinsp.
- EBCDIC ASCII
- tab
- X'05' X'09'
- CR
- X'0D' X'0D'
- LF
- X'25' X'0A'
- 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 Janus SocketsR documents the HttpRequest object, whose
AddXml method 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
- XmlDoc does not contain an Element.
- Options 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.