AddComment (XmlDoc/XmlNode function)

From m204wiki
Jump to navigation Jump to search

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.


[%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 not include EBCDIC characters that do not translate to Unicode. As of Sirius Mods Version 7.6, the content of an XmlDoc is maintained in 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.


  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><b>05</b></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> <b> 05 <!--this is comment 2--> </b> </a> </top>

  2. In the following example under Sirius Mods Version 7.6 or higher, a comment is added which uses a Unicode character, 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:

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

  3. For additional examples of working with Unicode characters in an XmlDoc, see item Adding characters that are represented by character references.

Request-cancellation errors

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • Object 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.