Not able to get the NODE-VALUE from XML file

skunal

Member
I have written the code to read the XML files as shown in the code section. But i am not able to get the value . Only the node name is come but not the value . Can anyone let me know whats the issue is
Code:
DEF VAR hDoc AS HANDLE NO-UNDO.
DEF VAR hRoot AS HANDLE NO-UNDO.
DEF VAR good AS LOGICAL NO-UNDO.
DEF VAR cXML AS LONGCHAR NO-UNDO.
/* THIS IS THE XML FILE I AM TRYING TO READ */
/*  "<?xml version='1.0' encoding='UTF-8'?>
<retConsStatServ xmlns='http://www.test.com' versao='1.07'>
<tpAmb>2</tpAmb>
<verAplic>SP_NFE_PL_005a_R01</verAplic>
<cStat>107</cStat>
<xMotivo>Serviço em Operação</xMotivo>
<cUF>35</cUF>
<dhRecbto>2008-06-14T12:07:48</dhRecbto>
<tMed>1</tMed>
</retConsStatServ>".  */
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
hDoc:LOAD("file","12345.xml",FALSE). /*** Pega valor de uma variável ***/
/*hDoc:LOAD("file","XML\ConsultaStatus_v107_resposta.xml",FALSE). 
/*** Pega valor de um arquivo externo ***/ */
message "##" error-status:get-message(1) skip
      error-status:get-message(2) skip
      error-status:get-message(3) view-as alert-box.
 
if ERROR-STATUS:ERROR then
   message "Test error" view-as alert-box.
else
   message "NO error" view-as alert-box.
hDoc:GET-DOCUMENT-ELEMENT(hRoot).
message "hRoot : " view-as alert-box.
RUN GetChildren(hRoot, 1).
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
PROCEDURE GetChildren:
DEF INPUT PARAMETER hParent AS HANDLE NO-UNDO.
DEF INPUT PARAMETER level AS INTEGER NO-UNDO.
DEF VAR i AS INTEGER NO-UNDO.
DEF VAR hNoderef AS HANDLE NO-UNDO.
define variable c as character no-undo.
CREATE X-NODEREF hNoderef.
 REPEAT i = 1 TO hParent:NUM-CHILDREN:
 good = hParent:GET-CHILD(hNoderef,i).
 IF NOT good THEN
 LEAVE.
 IF hNoderef:SUBTYPE <> "element" THEN
 NEXT.
        
 c = hNoderef:NODE-VALUE.
 MESSAGE "hNoderef:NAME : " hNoderef:name SKIP
 "hNoderef:NODE-VALUE : " hNoderef:node-value SKIP
 "hNoderef:ATTRIBUTE-NAMES : " hNoderef:ATTRIBUTE-NAMES
 VIEW-AS ALERT-BOX.
  RUN GetChildren(hNoderef, (level + 1)).
 END.
DELETE OBJECT hNoderef.
END PROCEDURE.
 

Marian EDU

Member
Code:
 IF hNoderef:SUBTYPE <> "element" THEN
 NEXT.

the value of a 'element' tag is a child node of the element having the type 'text' (i think), so you need to get down one extra level if the element have child nodes (and it should have if it has a value), on that child node you can use node-value attribute.
 

skunal

Member
Hi thanks a lot for the reply , can you please see my code and tell where exactly i should drill down again. because the after the "element" next statement also i am able to get the name of the node in this MESSAGE "hNoderef:NAME : " hNoderef:name(This coming fine) SKIP BUT the next statements ---> "hNoderef:NODE-VALUE : " hNoderef:node-value SKIP
"hNoderef:ATTRIBUTE-NAMES : " hNoderef:ATTRIBUTE-NAMES values are not displayed...I am not able to get when node name is being displayed how value is not getting displayed.
 
Top