why I am getting error "X-noderef must be associated with a valid x-document inorder to use it in method NUM-CHILDREN (9102)")

nen

New Member
/*My code is given below ......Here I want to read an xmlfile and write to temp-table . From this xml file I want to read only mainsub(child) and its sub-children(sub) */

XML:
DEFINE VARIABLE hDoc   AS HANDLE  NO-UNDO.

DEFINE VARIABLE hroot AS HANDLE  NO-UNDO.

DEFINE VARIABLE hmainsub  AS HANDLE  NO-UNDO.

DEFINE VARIABLE hsub AS HANDLE  NO-UNDO.

DEFINE VARIABLE hfield AS HANDLE  NO-UNDO.

DEFINE VARIABLE htext AS HANDLE  NO-UNDO.

DEFINE VARIABLE hBuf AS HANDLE NO-UNDO.

DEFINE VARIABLE hDBFld AS HANDLE NO-UNDO.

DEFINE VARIABLE ix     AS INTEGER NO-UNDO.

DEFINE VARIABLE jx     AS INTEGER NO-UNDO.

DEFINE VARIABLE cx     AS INTEGER NO-UNDO.



DEFINE TEMP-TABLE tttemp

FIELD ID      AS CHAR

FIELD SUFFIX      AS CHAR

FIELD PREFIX     AS CHAR

FIELD FIRST_NAME    AS CHAR

FIELD MIDDLE_NAME      AS CHAR

FIELD LAST_NAME    AS CHAR

FIELD DOB      AS CHAR

FIELD AGE      AS CHAR.

hBuf = BUFFER tttemp:HANDLE.   



CREATE X-DOCUMENT hDoc.

CREATE X-NODEREF hroot.

CREATE X-NODEREF hmainsub.

CREATE X-NODEREF hsub.

CREATE X-NODEREF hfield.

CREATE X-NODEREF htext.





hDoc:LOAD("file", "C:\samplefile.xml", FALSE).



hDoc:GET-DOCUMENT-ELEMENT(hroot).

REPEAT ix = 1 TO hroot:NUM-CHILDREN:

hroot:GET-CHILD(hmainsub,ix).

  

    IF  hmainsub:NAME = "mainsub" THEN

    DO:

         REPEAT cx = 1 TO hmainsub:NUM-CHILDREN:

         CREATE ttPilots.

           REPEAT jx = 1 TO hsub:NUM-CHILDREN:

           hsub:GET-CHILD(hfield, jx).

           IF hField:NUM-CHILDREN < 1 THEN NEXT.

           hDBFld = hBuf:BUFFER-FIELD(hField:NAME).

           hfield:GET-CHILD(htext, 1).

           hDBFld:BUFFER-VALUE = hTEXT:NODE-VALUE.

           END.

         END.

    END.

END.

DELETE OBJECT hDoc.

DELETE OBJECT hmainsub.

DELETE OBJECT  hsub.

DELETE OBJECT htext.

DELETE OBJECT  hfield.

DELETE OBJECT  hroot.



/* show data made it by displaying temp-table */

FOR EACH tttemp:

  DISPLAY tttemp  WITH 1 COLUMN.

END.

/*After running this code ...I keep on getting error code 9102.....xmlfile have been attached as " samplexmlfile.txt"*/
 

Attachments

  • samplexmlfile.txt
    714 bytes · Views: 4

Stefan

Well-Known Member
0. enable -debugalert so that you know which line is throwing that error
1. you are referencing hsub (with :num-children) before ensuring that hsub is pointing to an actual node.

Add:
Code:
hmainsub:get-child( hsub, cx )
 

nen

New Member
0. enable -debugalert so that you know which line is throwing that error
1. you are referencing hsub (with :num-children) before ensuring that hsub is pointing to an actual node.

Add:
Code:
hmainsub:get-child( hsub, cx )

Got it.....Thank you sir for pointing it.....
 
Top