Value (XmlDoc/XmlNode property)

From m204wiki
Revision as of 11:56, 10 May 2011 by Goff (talk | contribs) (move footer template to actual end (otherwise subsequent intervening text gets omitted); edits, tags and links)
Jump to navigation Jump to search

String-value of selected node (XmlDoc and XmlNode classes)

This settable property obtains a substring of the XPath "string-value" of a node, including its Text descendants. The string-value depends on the node type, as shown in "Usage Notes", below.

Syntax

%currentUnicode = nr:Value[( [xpath])] nr:Value[( [xpath])] = newUnicode Throws XPathError

Syntax terms

%currentUnicode A Unicode string that is the string-value of the context node. Prior to "Sirius Mods" Version 7.6, this is an EBCDIC string.
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 An XPath expression that results in a nodelist, the head of which is the node to process. An optional argument, its default is a period (.), that is, the node referenced by the method object (nr).
newUnicode A Unicode string that is the string-value to assign to the context node's Value property. Prior to "Sirius Mods" Version 7.6, this is an EBCDIC string.

Usage notes

  • As of "Sirius Mods" Version 7.3, the string terms in the method syntax may include only non-null EBCDIC characters that translate to Unicode. As of "Sirius Mods" Version 7.6, these strings are Unicode or are converted to Unicode.

    For more information about the effects of this Version 7.6 change, see "Strings and Unicode with the XmlDoc API". For an example of a specific effect that involves the Value method, see this example, below.

  • The string-value of a node depends on the node's type:
    Node type
    String-value
    Attribute
    The "normalized attribute value"
    Comment or Text
    The content of the node
    Element or Root
    The concatenation of the value of all its Text descendants, in document order
    PI
    The portion of the processing instruction following its target and any whitespace immediately following the target
  • Value is not allowed to be set if the head of the argument XPath result is the Root or is an Element with a non-text child.

Examples

  1. The following example displays the string "Hello, world!":

    begin %d object xmlDoc %d = new %d:loadXml('<t><a>Hell</a>' with '<b>o, world!'</b></t>') print %d:value('/t') end

  2. The following example assigns a new value to the "billRate" element:

    %worker:value('billRate') = %worker:value('billRate') - 10

  3. In the following request, run under "Sirius Mods" Version 7.6 or greater, an ampersand (&) in an Element value is returned by the Value method and displayed by two Print statements.

    begin %d object xmlDoc auto new %nodex is xmlNode %nodey is xmlNode %ebc is longstring %nodey = %d:addElement('top') %nodex = %nodeY:addElement('abc', 'Jack & Jill') %ebc = %nodex:value print %ebc print %nodex:value end

    The result is:

    Jack & Jill Jack &amp; Jill

    Because the Unicode string returned from Value in the example above is assigned to an EBCDIC variable before it is printed for the first time, the initial Print statement simply displays the EBCDIC variable value as is. The assignment to EBCDIC causes a straight character-by-character conversion using the current Unicode translation tables.

    The second Print statement has to convert the Unicode value returned by the Value expression. For this, under "Sirius Mods" Version 7.6 or greater, Print uses character encoding for any Unicode characters that do not translate to EBCDIC, and an ampersand is converted to to the string &amp;. In effect, Print calls the UnicodeToEbcdic method with parameter setting CharacterEncode=True to implicitly convert the Unicode value.

Request-Cancellation Errors

  • XPath is invalid.
  • Result of (XPath) is empty.
  • Insufficient free space exists in CCATEMP.

See also

  • valueDefault is a function that obtains a node's string value and that allows an empty XPath result.
  • For more information about using XPath expressions, see XPath.