Kbase P100203: Cannot write recursive 4GL procedure to create XML file
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/12/2007 |
|
Status: Unverified
SYMPTOM(s):
Parenting an XML node to another node at the same level and type causes error 9082.
X-NODEREF or X-DOCUMENT <method-name> got an error: <xml-exception>. (9082)
X-NODEREF or X-DOCUMENT APPEND-CHILD got an error: A node was inserted where it doesn't belong. (9082)
Cannot write 4GL recursive procedure to create an XML file
The XML file is being created with recursive 4GL code.
CAUSE:
There is a node handle that the 4GL is trying to re-use when calling the recursive procedure. For example the following code will result in the error because the child node has been created and already appended to a parent node. But the recursive procedure tries to allocate this handle to new nodes as they are created.
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE h_Child AS HANDLE NO-UNDO.
CREATE X-NODEREF h_Child.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
hDoc:CREATE-NODE(hRoot,"Main","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
RUN addNode (INPUT hRoot, INPUT "1").
PROCEDURE addNode:
DEFINE INPUT PARAMETER h_Parent AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER cInt AS CHARACTER NO-UNDO.
IF int(cInt) > 100 THEN LEAVE.
hDoc:CREATE-NODE(h_Child,"Child","ELEMENT").
h_Child:SET-ATTRIBUTE("NodeText",cInt).
h_Parent:APPEND-CHILD(h_Child).
RUN addNode (INPUT h_Child, INPUT string(int(cInt) + 1)).
END PROCEDURE.
hDoc:SAVE("file","test.xml").
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
FIX:
Create a new child node with each call to the recursive procedure. For example:
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
hDoc:CREATE-NODE(hRoot,"Main","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
RUN addNode (INPUT hRoot, INPUT "1").
PROCEDURE addNode:
DEFINE INPUT PARAMETER h_Parent AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER cInt AS CHARACTER NO-UNDO.
DEFINE VARIABLE h_Child AS HANDLE NO-UNDO.
CREATE X-NODEREF h_Child.
IF int(cInt) > 100 THEN LEAVE.
hDoc:CREATE-NODE(h_Child,"Child","ELEMENT").
h_Child:SET-ATTRIBUTE("NodeText",cInt).
h_Parent:APPEND-CHILD(h_Child).
RUN addNode (INPUT h_Child, INPUT string(int(cInt) + 1)).
DELETE OBJECT h_child.
END PROCEDURE.
hDoc:SAVE("file","test.xml").
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.