Consultor Eletrônico



Kbase P166353: How to retrieve the text value of an XML node in 4GL / ABL
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/19/2010
Status: Unverified

GOAL:

How to retrieve the text value of an XML node in 4GL / ABL

GOAL:

How to get the text value between two XML element tags

GOAL:

How to access a TEXT node in an XML document

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x

FIX:

The text area between two XML element tags is itself a separate node, which is a child node of the element it is within. Such nodes always have the name "#text" and a SUBTYPE attribute of TEXT. This node exists even if there is no text between the element tags, and even if the element has ELEMENT child nodes as well.
An element may have more than one TEXT child node ; if it has one or more ELEMENT child nodes, there will be a TEXT child node before and after each ELEMENT node. For example, an element with one ELEMENT child node will have two TEXT child nodes: one before the ELEMENT child and one after it. An element with two ELEMENT child nodes will have three TEXT child nodes: one before the first ELEMENT child node, one between the first and second ELEMENT child nodes, and one after the last ELEMENT child node. Normally, useful text values are found in a single TEXT node between two matching element tags. However, it is important to remember that the text nodes between other ELEMENT tags exist in order to properly interpret the NUM-CHILDREN attribute of the parent node and the results of its GET-CHILD() method.
To access the value of a TEXT node in 4GL / ABL, first navigate to the parent ELEMENT node. Then call the GET-VALUE() method of its child nodes to access the text. For example:
/* Check for an ELEMENT node with only one child node of subtype TEXT */
IF hNoderef:SUBTYPE <> "element" THEN NEXT.
IF hNoderef:NUM-CHILDREN < 1 THEN NEXT.
lGood = hNoderef:GET-CHILD(hTEXT, 1).
IF lGood THEN
IF hNoderef:NUM-CHILDREN = 1 AND hTEXT:SUBTYPE = 'TEXT' THEN
MESSAGE
'Name:' hNoderef:NAME
SKIP
'Text value:' hTEXT:NODE-VALUE
VIEW-AS ALERT-BOX.