Print (XmlDoc/XmlNode subroutine): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 9: Line 9:
<tr><th>nr</th>
<tr><th>nr</th>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. If an <var>XmlDoc</var>, the Root node is the context node. </td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. If an <var>XmlDoc</var>, the Root node is the context node. </td></tr>
<tr><th>XPath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> 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 (<i>nr</i>). </td></tr>
<td>A <var>Unicode</var> 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 (<i>nr</i>). </td></tr>
<tr><th>options</th>
<tr><th>options</th>
Line 22: Line 22:


<li><b>Compact</b>, <b>Expanded</b>, <b>AttributeCompact</b>, <b>ElementCompact</b>, or <b>BothCompact</b> <br>
<li><b>Compact</b>, <b>Expanded</b>, <b>AttributeCompact</b>, <b>ElementCompact</b>, or <b>BothCompact</b> <br>
 
One of these mutually exclusive [[XmlDoc API serialization options#outformat|output formats]], which control the degree of expansion or compression of the display of a serialized element's content.  
<li>One of the following mutually exclusive '''output formats''': <ul> <li><b>Compact</b>
This is the default. An element's entire start tag is printed on a single line, which includes attributes and namespace declarations. If it has no children or has a single Text child, and does '''not''' have attributes nor namespace declarations, then the Text child is serialized on the same line as the start and end tags. For example: <pre>    <top>        <in1 a="xyz" b="foo">          content1        </in1>        <in2>content2</in2>    </top> </pre> <li><b>Expanded</b>
A new line is started for each attribute, namespace declaration, and child. For example: <pre>    <top>        <in1          a="xyz"          b="foo"        >          content1        </in1>        <in2>          content2        </in2>    </top> </pre> <li><b>AttributeCompact</b>
Attributes and namespace declarations are printed on the same line as the start tag. For example: <pre>    <top>        <in1 a="xyz" b="foo">          content1        </in1>        <in2>          content2        </in2>    </top> </pre> <li><b>ElementCompact</b>
An entire element is printed on one line, if it has no attributes nor namespace declarations and has no children other than possibly a Text child. For example: <pre>    <top>        <in1          a="xyz"          b="foo"          >          content1        </in1>        <in2>content2</in2>    </top> </pre> <li><b>BothCompact</b>
The most compacted format, this combines the effect of AttributeCompact and ElementCompact. It displays on one line an element that has no children or that has a single Text child. For example: <pre>    <top>        <in1 a="xyz" b="foo">content1</in1>        <in2>content2</in2>    </top> </pre> </ul>


<li><b>NoEmptyElt</b><br>
<li><b>NoEmptyElt</b><br>
Line 37: Line 31:


<li><b>SortCanonical</b><br>  
<li><b>SortCanonical</b><br>  
 
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 <var>ExclCanonical</var> option.


<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br>
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b><br>
Ensures that 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 [[Version (XmlDoc property)|Version]] property is a non-null string, if the <var>XmlDoc</var> is not empty,
and if the top of the subtree being serialized is the <var>Root</var> node.
and if the node selected by <var class="term">xpath</var> is the <var>Root</var> node. <var>AllowXmlDecl</var> is the default.  
 
<li><b>AllowXmlDecl</b> or <b>NoXmlDecl</b>
 
Whether or not the XML declaration (<?xml version=...?>) is produced &mdash; if the XML version number (as returned by the [[Version (XmlDoc property)|Version]] is not the null string, and the node selected by <i>XPath</i> is the Root. AllowXmlDecl is the default. AllowXmlDecl and NoXmlDecl may not both be specified.  


</ul></td></tr>
</ul></td></tr>

Revision as of 23:37, 14 February 2011

Print selected subtree (XmlDoc and XmlNode classes)


This 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, which are identified below and described in greater detail in "XmlDoc API serialization options":
  • 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.
  • Indent n
    Indent Element children (and, depending on the compaction option, below, in effect, attributes and the closing characters "/>" of an empty Element) n spaces (default 3) from the beginning of the Element's Start-Tag.
  • 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.
  • 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).
  • 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.

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.
  • The Print method output is not affected if one of the output format options or Indent is specified, and an element to be serialized has the xml:space="preserve" or xml:space="default" attribute.
  • As of version 6.7, the Print 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 tab, carriage return, and linefeed characters for the following XML document node types:
    • Attribute
    • Text

    These character references are used:

    tab
    &#x9;
    CR
    &#xD;
    LF
    &#xA;

    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 &quot;. Prior to version 7.6, this convention was not strictly observed.
  • As of Sirius Mods version 7.6, XmlDoc content is stored in Unicode. To serialize to EBCDIC, the Print method uses the Unicode tables (described further in ?? refid=u80.) to convert the XmlDoc content.

Example

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>

Request-Cancellation Errors

  • XPath is invalid.
  • Result of (XPath) is empty.
  • Options 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 ?? reftxt=Audit refid=audit. and ?? reftxt=Trace refid=trace., inserts line breaks and performs indentation.
  • Additional serializing methods include: