WebSend (XmlDoc subroutine)
Serialize XmlDoc as Web response
WebSend is a member of the XmlDoc class.
This subroutine converts an XmlDoc to its textually represented XML document to be sent in a response on a Janus Web Server thread. (The process of converting to a text string is called serialization, because the text representation of a document is called the serial form).
The serialized output of WebSend is a UTF-8 text string. This output is added to the output buffer that is sent by a subsequent invocation of $Web_done or $Web_form_done.
- An expression that points to the XmlDoc whose content is to be serialized.
- Any combination of the following options (but single occurrences only):
- AllowXmlDecl or NoXmlDecl AllowXmlDecl, the default, produces the XML declaration (that is, <?xml&thinsp.version=...?>) if the declaration was set (see Version). NoXmlDecl indicates that the XML declaration is not produced.
- Indent n
Inserts space characters (and line-ends, as described for the next option)
into the serialized string such that
if the string is broken 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.
For example, Indent 2 would produce spacing like the following:
<top> <leaf1 xx="yy">value</leaf1> <sub> <leaf2>value</leaf2> </sub> </top>
n is a non-negative integer, and its maximum value (as of Sirius Mods version 7.0) is 254.
Indent may be used with one of the line-end options, above, including Newline. If Indent is specified and no line-end options are also specified, Newline is implied.
- One of the line-end options below, to provide line breaks in
the output after any of the following is serialized:
- An element start-tag, if it has any non-text node children
- An empty element tag, or an empty element end-tag
- A processing instruction (PI)
- A comment
- A text node, if it has any siblings
- Insert a carriage-return character as the line-end sequence in the above cases.
- Insert a linefeed character as the line-end sequence in the above cases.
- Insert a carriage-return character followed by a linefeed character as the line-end sequence in the above cases.
- Insert the line-end sequence defined for this Janus Web Server connection (by the JANUS DEFINE command or $WEB_SET) as the line-end sequence in the above cases.
This indicates that an empty element is serialized with its start tag
followed by an end tag.
If this option is not specified, the default is to serialize an empty element with an empty element tag:
An Element node that has no children and
no Attributes will not be serialized, unless it is the top level Element in
the subtree being serialized.
The serialization of a child-less and Attribute-less Element is omitted,
even if the Element's serialization would contain
Namespace declarations in its start tag.
If an Element node has no Attributes, but has (only) Element children
(one or more), and all of its children are Attribute-less and child-less,
then that parent Element is serialized, even though its content in the
serialization is empty.
That parent is serialized with a start tag and an end tag
(and an inserted line separator, if called for by the serializing
method's parameter options).
For example, if the Serial method display of an XmlDoc in tree format
is the following when OmitNullElement is not specified:
<top> <middle> <empty/> <p:empty2 xmlns:p="uri:stuff"/> </middle> </top>
Here is the display of the XmlDoc with the OmitNullElement option specified:
<top> <middle> </middle> </top>
The OmitNullElement option is available as of Sirius Mods version 7.3.
- SortCanonical This indicates that namespace declarations (based on the prefix being declared) and attributes (based on the namespace URI followed by the local name) are serialized in sorted order. This can be useful, for instance, when using the Serial method to serialize a portion of an XML document for a signature. The sort order for namespace declarations and attributes is from lowest to highest, and it uses the Unicode code ordering (for example, numbers are lower than letters). Added in Sirius Mods version 6.9 as a step towards support for canonicalization, this option is superseded by the Serial method ExclCanonical option (?? refid=exclcan.), which provides full support for canonicalized serialization.
- 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..
- The output line-breaking options make the serialized stream easier to read, for example, for a browser's “view page source” facility to display XHTML produced with Janus SOAP.
- As of version 6.7, the WebSend 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:
The EBCDIC and corresponding ASCII encodings of the characters is:
- EBCDIC ASCII
- X'05' X'09'
- X'0D' X'0D'
- 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.
The following Janus Web Server program uses WebReceive to obtain the XML document from the HTTP request, then uses WebSend to buffer some of the received data:
Begin %d Object XmlDoc %d = New %d:WebReceive %d2 Object XmlDoc %d2 = New %d2:LoadXml('<sum>' With - %d:Value('/*/*') + %d:Value('/*/*') - With '</sum>') %d2:WebSend End
- XmlDoc does not contain an Element.
- options is invalid.
- Insufficient free space exists in CCATEMP.