Print (XmlDoc/XmlNode subroutine): Difference between revisions

From m204wiki
Jump to navigation Jump to search
Line 44: Line 44:


==Examples==
==Examples==
In the following example, the <var>Print</var> method is called first in its default form with no arguments, then with explicit values for its options:
<ol>
<li>In the following example, the <var>Print</var> method is called first in its default form with no arguments, then with explicit values for its options:
<p class="code">begin
<p class="code">begin
   print 'Print method'
   print 'Print method'
Line 76: Line 77:
  </top></nowiki>
  </top></nowiki>
</p>
</p>
In the following fragment, the <var>Print</var> result for a document with untranslatable Unicode is shown:
<li>In the following fragment, the <var>Print</var> result for a document with untranslatable Unicode is shown:
<p class="code">%doc2:[[AddElement_(XmlDoc/XmlNode_function)|addElement]]('circumference', -
<p class="code">%doc2:[[AddElement_(XmlDoc/XmlNode_function)|addElement]]('circumference', '2 * &amp;#x3C0; * r':U)
  '2 * &amp;#x3C0; * r':U)
%doc2:print
%doc2:print
</p>
</p>
Line 84: Line 84:
<p class="output"><circumference>2 * &amp;#x03C0; * r</circumference>
<p class="output"><circumference>2 * &amp;#x03C0; * r</circumference>
</p>
</p>
</ol>


==Request-cancellation errors==
==Request-cancellation errors==

Revision as of 21:51, 20 March 2012

Print selected subtree (XmlDoc and XmlNode classes)

The Print subroutine displays an XmlDoc subtree in a readable form, useful for debugging, for example.

Syntax

nr:Print[( [xpath], [options])] Throws XPathError

Syntax terms

nr An XmlDoc or XmlNode, used as the context node for the XPath expression. If an XmlDoc, the Root node is the context node.
xpath A Unicode string that is an XPath expression that results in a nodelist, the head of which is the top of the subtree to print. An optional argument, its default is a period (.), that is, the node referenced by the method object (nr).
options A blank delimited string that can contain one or more of the following options.
Note: These options are described in greater detail in "XmlDoc API serialization options".
  • AllowXmlDecl or NoXmlDecl
    Whether or not the serialization will contain the "XML Declaration" (<?xml version=...?>), if the value of the Version property is a non-null string, if the XmlDoc is not empty, and if the node selected by xpath is the Root node. AllowXmlDecl is the default.
  • CharacterEncodeAll
    Use character encoding in all contexts (that is, not only in Attribute or Element values) to display Unicode characters that do not translate to EBCDIC.
  • Compact, Expanded, AttributeCompact, ElementCompact, or BothCompact
    One of these mutually exclusive output formats, which control the degree of expansion or compression of the display of a serialized element's content.
  • Indent n
    Indent Element children (and, depending on the compaction option, above, in effect, attributes and the closing characters "/>" of an empty Element) n spaces (default 3) from the beginning of the Element's Start-Tag.
  • NoEmptyElt
    Deprecated as of Sirius Mods Version 7.0, serializes all empty elements with a start tag followed by an end tag. The default is to serialize an empty element with an empty element tag (as in <middleName/>).
  • OmitNullElement
    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.
  • SortCanonical
    This deprecated option serializes namespace declarations and attributes in sorted order (from lowest to highest with Unicode code ordering).

Usage notes

  • Options may be specified in any case. For example, you can use either NoXmlDecl or noxmldecl, interchangeably.
  • As a debugging aide, Print may be issued for the root node of an XmlDoc that is not well-formed, that is, does not contain an Element.
  • 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 &quot;. Prior to Sirius Mods Version 7.6, this convention was not strictly observed.

Examples

  1. In the following example, the Print method is called first in its default form with no arguments, then with explicit values for its options:

    begin print 'Print method' print '***********' %doc is object xmlDoc %doc = new call %doc:loadXml('<top><a><b>05</b></a><a2/></top>') %doc:Version ='1.0' call %doc:print print 'Non-default display:' call %doc:print('/', 'NoXmlDecl NoEmptyElt Indent 6 Expanded') end

    The example results follow:

    <?xml version="1.0"?> <top> <a> <b>05</b> </a> <a2/> </top> Non-default display: <top> <a> <b> 05 </b> </a> <a2> </a2> </top>

  2. In the following fragment, the Print result for a document with untranslatable Unicode is shown:

    %doc2:addElement('circumference', '2 * &#x3C0; * r':U) %doc2:print

    The result follows (the Unicode codepoint for the Greek letter π has the hexadecimal value 03C0):

    <circumference>2 * &#x03C0; * r</circumference>

Request-cancellation errors

  • The xpath expression is invalid.
  • The result of xpath is empty.
  • options values are invalid.
  • Insufficient free space exists in CCATEMP.

See also

  • For more information about using XPath expressions, see "XPath".
  • To more accurately serialize an XmlDoc, as opposed to providing a "displayable" form, use the Serial function. The Print subroutine, like its analogs Audit and Trace, inserts line breaks and performs indentation.
  • See the description of Unicode to EBCDIC conversion performed by Print.
  • Additional serializing methods include: