Problems with xml files progress v9.1D Help me please.

spenyas

New Member
Hi:
Sorry for my english . I´m working with 9.1D and i´m trying to read xml files but i can´t read lines when it isn´t in a node.

For example:
<?xml version="1.0" encoding="utf-8"?>
<apunte dbstatus="alta">
<codigo></codigo> /* iCan´t read this line */
<fechaini>06/02/2007</fechaini> /* iCan´t read this line */
<horaini>10:00:00</horaini> /* iCan´t read this line */
<fechafin>06/02/2007</fechafin> /* iCan´t read this line */
<horafin>19:00:00</horafin> /* iCan´t read this line */
<titulo></titulo> /* iCan´t read this line */
<contenido></contenido> /* iCan´t read this line */
<precio></precio> /* iCan´t read this line */
<secciones>
<seccion>
<codigo></codigo>
<descripcion></descripcion>
</seccion>
</secciones>
</apunte>

I used this code:
DEFINE STREAM sFicheros.
DEFINE STREAM sSalida.
OUTPUT STREAM sSalida TO 'Z:\cmt\INTERCAMBIO\EUROPA PRESS\datos_fichero.txt'.
RUN Lecturaxml (INPUT 'c:\file.xml').

/******************* PROCEDURES *******************/
PROCEDURE Lecturaxml:
DEFINE INPUT PARAMETER cFichero AS CHARACTER NO-UNDO.

DEF VAR hDoc AS HANDLE.
DEF VAR hRoot AS HANDLE.
DEF VAR res AS LOGICAL.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.

hDoc:LOAD("file",cFichero,FALSE).

hdoc:GET-DOCUMENT-ELEMENT(hRoot).

res = DYNAMIC-FUNCTION('getChild':U ,INPUT hRoot, INPUT 0).
IF NOT res THEN MESSAGE "No se puede leer el documento" VIEW-AS ALERT-BOX.
DELETE OBJECT hRoot.
DELETE OBJECT hDoc.
END.

/******************* FUNCIONES *******************/
FUNCTION getChild RETURNS LOGICAL
(INPUT hNode AS HANDLE,
INPUT xLevel AS INTEGER
):

DEF VAR i AS INTEGER.
DEF VAR j AS INTEGER.
DEF VAR hNodeRef AS HANDLE.
DEF VAR hNodeRefChild AS HANDLE.
DEF VAR hText AS HANDLE.
DEF VAR res AS LOGICAL.
DEFINE VARIABLE cAux AS CHARACTER NO-UNDO.

CREATE X-NODEREF hNodeRef.
CREATE X-NODEREF hNodeRefChild.
CREATE X-NODEREF hText.
REPEAT i = 1 TO hNode:NUM-CHILDREN:
res = hNode:GET-CHILD(hNodeRef,i).

IF NOT res THEN LEAVE.
ELSE DO:
DO j = 1 TO hNodeRef:NUM-CHILDREN:
hNodeRef:GET-CHILD(hNodeRefChild,j).
IF hnoderefchild:NUM-CHILDREN < 1 THEN NEXT.
hNodeRefChild:GET-CHILD(htext,1).
PUT STREAM sSalida UNFORMATTED CAUX CHR(9) htext:NODE-VALUE SKIP. /* i want to put the tag and the node-value , "horaini" + chr(9) + "10:00:00" */
END.
END.
getChild(hNodeRef, (xLevel + 1)).
END.
DELETE OBJECT hNodeRef.
RETURN TRUE.
END FUNCTION.

2 QUESTION:
How i can read the lines that i can´t read or what is wrong in my code?
i Have a var CAUX , i would like, to put into CAUX the tag i´m reading. for example CAUX contains "titulo" or "codigo". How i Can do it??

Thanks.
 
Back
Top