AddComment (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 8: Line 8:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th><i>%nod</i></th>
<tr><th><i>%nod</i></th>
<td>If specified, an XmlNode that is set to point to the Comment node that is added. </td></tr>
<td>If specified, an <var>XmlNode</var> that is set to point to the Comment node that is added. </td></tr>
<tr><th><i>nr</i></th>
<tr><th><i>nr</i></th>
<td>An XmlDoc or XmlNode that refers to the Root or Element node that is the parent of the added Comment node. </td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var> that refers to the Root or Element node that is the parent of the added Comment node. </td></tr>
<tr><th><i>value</i></th>
<tr><th><i>value</i></th>
<td>A Unicode string that is the value of the added Comment node; stored exactly as is, that is, without whitespace normalization.</td></tr>
<td>A <var>Unicode</var> string that is the value of the added Comment node; stored exactly as is, that is, without whitespace normalization.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>Since the return value of AddComment is frequently not needed,
<li>Since the return value of <var>AddComment</var> is frequently not needed,
you may want to Call it instead of saving its return value.
you may want to Call it instead of saving its return value.
<li>Processing of an XmlDoc is likely to be more efficient if
<li>Processing of an <var>XmlDoc</var> is likely to be more efficient if
you add nodes in document
you add nodes in document
order (that is, top-to-bottom, left-to-right).
order (that is, top-to-bottom, left-to-right).
<li>As of ''Sirius Mods'' version 7.3, ''value'' may
<li>As of ''Sirius Mods'' version 7.3, ''value'' may
include only non-null EBCDIC characters that translate to Unicode.
include only non-null EBCDIC characters that translate to <var>Unicode</var>.
As of ''Sirius Mods'' version 7.6, all [[Janus SOAP]] string arguments and results are Unicode
As of ''Sirius Mods'' version 7.6, all [[Janus SOAP]] string arguments and results are <var>Unicode</var>
or are converted to Unicode.
or are converted to <var>Unicode</var>.
For more information about the effects of this version 7.6
For more information about the effects of this version 7.6
change, see [[Strings and Unicode]].
change, see [[Strings and Unicode]].
<li>To modify the value stored in an Comment node,
<li>To modify the value stored in an Comment node,
change the Value property of an XmlNode that points to
change the Value property of an <var>XmlNode</var> that points to
the Comment node.
the Comment node.
</ul>
</ul>
Line 38: Line 38:
of the root node, and one is added as the last child of element "b":
of the root node, and one is added as the last child of element "b":
<p class="code">Begin
<p class="code">Begin
%doc is Object XmlDoc
%doc is <var>Object</var> <var>XmlDoc</var>
%doc = New
%doc = New
%doc:LoadXml('<top><a><b>05</b></a></top>')
%doc:LoadXml('<top><a><b>05</b></a></top>')
%n1 is Object XmlNode
%n1 is <var>Object</var> <var>XmlNode</var>
Call %doc:AddComment('this is comment 1')
Call %doc:<var>AddComment</var>('this is comment 1')
%n1 = %doc:SelectSingleNode('top/a/b')
%n1 = %doc:SelectSingleNode('top/a/b')
Call %n1:AddComment('this is comment 2')
Call %n1:<var>AddComment</var>('this is comment 2')
Call %doc:Print
Call %doc:Print
End
End
Line 60: Line 60:
<!--this is comment 1-->
<!--this is comment 1-->
</p>
</p>
<li>In the following example under ''Sirius Mods'' 7.6 or higher, a Unicode character
<li>In the following example under ''Sirius Mods'' 7.6 or higher, a <var>Unicode</var> character
comment is added, then printed twice.
comment is added, then printed twice.
The Print statement succeeds only if its <tt>CharacterEncodeAll</tt> option
The Print statement succeeds only if its <tt>CharacterEncodeAll</tt> option
is specified, because the Unicode character (trademark) does not translate
is specified, because the <var>Unicode</var> character (trademark) does not translate
to an EBCDIC character.
to an EBCDIC character.
For such a character in an Element or Attribute value, however, the Print
For such a character in an Element or Attribute value, however, the Print
Line 69: Line 69:
require the CharacterEncodeAll option.
require the CharacterEncodeAll option.
<p class="code">Begin
<p class="code">Begin
%d Object XmlDoc Auto New
%d <var>Object</var> <var>XmlDoc</var> Auto New
%d:AddComment('&amp;#x2122;':U)
%d:<var>AddComment</var>('&amp;#x2122;':U)
%d:AddElement('a')
%d:AddElement('a')


Line 82: Line 82:
<a/>
<a/>
CANCELLING REQUEST: MSIR.0750: Class XMLDOC, subroutine
CANCELLING REQUEST: MSIR.0750: Class XMLDOC, subroutine
PRINT: Unicode character without valid translation to
PRINT: <var>Unicode</var> character without valid translation to
EBCDIC in line 9
EBCDIC in line 9
</p>
</p>


For additional examples of working with Unicode characters in an XmlDoc,
For additional examples of working with <var>Unicode</var> characters in an <var>XmlDoc</var>,
see item [[??]] refid=addunic..
see item [[??]] refid=addunic..
</ol>
</ol>
Line 103: Line 103:
<ul>
<ul>
<li>[[InsertCommentBefore (XmlNode function)|InsertCommentBefore]] also adds a Comment node.
<li>[[InsertCommentBefore (XmlNode function)|InsertCommentBefore]] also adds a Comment node.
AddComment adds a Comment as the last child of the node pointed to by the
<var>AddComment</var> adds a Comment as the last child of the node pointed to by the
method object;
method object;
InsertCommentBefore adds a Comment as the immediately preceding
InsertCommentBefore adds a Comment as the immediately preceding
sibling of the node pointed to by the method object.
sibling of the node pointed to by the method object.
</ul>
</ul>

Revision as of 17:46, 25 January 2011

Add Comment to XmlDoc Root or to Element XmlNode (XmlDoc and XmlNode classes)

[Requires Janus SOAP]


This callable function adds a Comment node as the last child of the Root node or Element node referenced by the method object.

Syntax

[%nod =] nr:AddComment( value)

Syntax terms

%nod If specified, an XmlNode that is set to point to the Comment node that is added.
nr An XmlDoc or XmlNode that refers to the Root or Element node that is the parent of the added Comment node.
value A Unicode string that is the value of the added Comment node; stored exactly as is, that is, without whitespace normalization.

Usage notes

  • Since the return value of AddComment is frequently not needed, you may want to Call it instead of saving its return value.
  • Processing of an XmlDoc is likely to be more efficient if you add nodes in document order (that is, top-to-bottom, left-to-right).
  • As of Sirius Mods version 7.3, value may include only non-null EBCDIC characters that translate to Unicode. As of Sirius Mods version 7.6, all Janus SOAP string arguments and results are Unicode or are converted to Unicode. For more information about the effects of this version 7.6 change, see Strings and Unicode.
  • To modify the value stored in an Comment node, change the Value property of an XmlNode that points to the Comment node.

Examples

  1. In the following example, one Comment node is added as the last child of the root node, and one is added as the last child of element "b":

    Begin %doc is Object XmlDoc %doc = New %doc:LoadXml('<top><a>05</a></top>') %n1 is Object XmlNode Call %doc:AddComment('this is comment 1') %n1 = %doc:SelectSingleNode('top/a/b') Call %n1:AddComment('this is comment 2') Call %doc:Print End

    The example result, showing the serialized format of the comments, follows:

    <top> <a> 05 </a> </top>

  2. In the following example under Sirius Mods 7.6 or higher, a Unicode character comment is added, then printed twice. The Print statement succeeds only if its CharacterEncodeAll option is specified, because the Unicode character (trademark) does not translate to an EBCDIC character. For such a character in an Element or Attribute value, however, the Print method automatically displays the XML hex representation and does not require the CharacterEncodeAll option.

    Begin %d Object XmlDoc Auto New %d:AddComment('&#x2122;':U) %d:AddElement('a') %d:Print(, 'CharacterEncodeAll') %d:Print End

    The result is:

    <a/> CANCELLING REQUEST: MSIR.0750: Class XMLDOC, subroutine PRINT: Unicode character without valid translation to EBCDIC in line 9

    For additional examples of working with Unicode characters in an XmlDoc, see item ?? refid=addunic..

Request-Cancellation Errors

  • Nr is neither the Root nor an Element node.
  • Argument value violates the rules for an XML comment.


See also

  • InsertCommentBefore also adds a Comment node. AddComment adds a Comment as the last child of the node pointed to by the method object; InsertCommentBefore adds a Comment as the immediately preceding sibling of the node pointed to by the method object.