Progress
External Program
Interfaces


Using Node Attributes and Values

You can get information about the child node by using various attributes and methods. For example, if you do not know how many nodes there are below the node referred to by the node reference, you can use the NUM-CHILDREN attribute. You can obtain or set the value of the node by using the NODE-VALUE attribute:

DEFINE VARIABLE hChNode AS HANDLE.
CREATE X-NODEREF hChNode.
REPEAT i = 1 TO hParent:NUM-CHILDREN:
    logvar = hParent:GET-CHILD(hChNode, i).
    IF hChNode:NODE-VALUE > 0 THEN
        hChNode:NODE-VALUE = hChNode:NODE-VALUE + i.
. . . 

You can obtain a list of an element’s attribute names using the ATTRIBUTE-NAMES attribute, get the value of an attribute by using the GET-ATTRIBUTE( ) method or set the value of an attribute by using the SET-ATTRIBUTE( ) method. You can also REMOVE-ATTRIBUTE( ):

. . .
REPEAT i = 1 TO hNode1:NUM-CHILDREN:
  logvar = hNode1:GET-CHILD(hChNode, i).
  IF NOT logvar THEN LEAVE.
  entries = hNode1:ATTRIBUTE-NAMES.
  REPEAT j = 1 TO NUM-ENTRIES(entries):
    aname = ENTRY(j, entries).
    MESSAGE "attrname is " aname "value is " hNode1:GET-ATTRIBUTE(aname).
  END.
END.
. . . 

In addition to creating nodes, you can IMPORT-NODE( ), CLONE-NODE( ), and DELETE-NODE( ). In addition to appending and getting a child, you can REMOVE-CHILD(), REPLACE-CHILD( ), and GET-PARENT( ). The following example demonstrates the CLONE-NODE( ) method:

e-clone.p
/* e-clone.p */
DEFINE VARIABLE hXref AS HANDLE.
DEFINE VARIABLE hXref1 AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.
DEFINE VARIABLE hText1 AS HANDLE.
DEFINE VARIABLE hClone AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hDoc AS HANDLE.

CREATE X-NODEREF hXref.
CREATE X-NODEREF hXref1.
CREATE X-NODEREF hText.
CREATE X-NODEREF hText1.
CREATE X-NODEREF hClone.
CREATE X-NODEREF hRoot.
CREATE X-DOCUMENT hDoc.

hDoc:CREATE-NODE(hRoot,"root","ELEMENT").
hDoc:INSERT-BEFORE(hRoot,?).
hDoc:CREATE-NODE(hXref,"customer","ELEMENT").
hDoc:CREATE-NODE(hXref1,"order","ELEMENT").
hDoc:CREATE-NODE(hText,?,"TEXT").
hDoc:CREATE-NODE(hText1,?,"TEXT").

/* Add the two element nodes to the root, each with a text*/
hXref:SET-ATTRIBUTE("id","54").
hXref:SET-ATTRIBUTE("name","Second Skin Scuba").
hRoot:APPEND-CHILD(hXref).
hXref:APPEND-CHILD(hText).

hXref1:SET-ATTRIBUTE("id","55").
hXref1:SET-ATTRIBUTE("name","Off the Wall").
hRoot:APPEND-CHILD(hXref1).
hXref1:APPEND-CHILD(hText1).
hText:NODE-VALUE = "hi from customer".
hText1:NODE-VALUE = "hi from order".

hXref1:CLONE-NODE(hClone,TRUE).
hRoot:APPEND-CHILD(hClone). 
/* Save the file */
hDoc:SAVE("file","clone1.xml").
DELETE OBJECT hXref.
DELETE OBJECT hXref1.
DELETE OBJECT hText.
DELETE OBJECT hText1.
DELETE OBJECT hClone.
DELETE OBJECT hRoot.
DELETE OBJECT hDoc. 

There are more methods and attributes that apply to the X-DOCUMENT object and the X-NODEREF objects. For more information on these attributes and methods, see their entries in the Progress Language Reference manual.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095