Leer variables de un fichero XLM

Leer variables de un fichero XLM

Postby Verhoven » Sun Jan 24, 2010 7:07 pm

Necesito leer unas variables que me entregan en un fichero en formato XLM.
Existe alguna función para realizarlo.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: Leer variables de un fichero XLM

Postby Manuel Aranda » Sun Jan 24, 2010 8:39 pm

Un fichero XML lo puedes tratar como un fichero plano y abrirlo con Fopen.
Ej.:
cTexto=memoread( "FICHERO.XML" )
//
nHandle:=FOpen("FICHERO.XML", FO_READWRITE + FO_SHARED)
//
IF FERROR() !=0
TONE(500,2)
MsgInfo("Error de apertura del fichero "+cFichero)
ELSE
FSeek( nHandle, 0, FS_SET )
nPos=AT("<IDENTIFICADORPFISICA>",cTexto)
FSeek(nHandle,nPos+22)
FRead(nHandle,@cNif,9)
............................................
.......................................
Un saludo,
Manuel

xH 1.2.3, FWH 23.07 32 bits, BC++ 7.4, xVerce CW 1.0, PellesC
User avatar
Manuel Aranda
 
Posts: 603
Joined: Wed Oct 19, 2005 8:20 pm
Location: España

Re: Leer variables de un fichero XLM

Postby thefull » Mon Jan 25, 2010 1:01 pm

Si bien la solución de Manuel Aranda es correcta, no creo que sea la solución, porque ¿ como deberías de obtener la propiedad ra del NODE1, si tenemos un XML de esta manera <NODE ra="jose"/> <NODE1 ra="pepe"/> ?

Para ello tienes clases relacionadas con XML, en este foro hay información sobre ello, ademas en xHarbour tienes en /doc documentación, pero a grandes rasgos;

Code: Select all  Expand view
#include "hbxml.ch"

  cXML := memoread( "tufichero.xml")

   oDoc := TXmlDocument():New( cXML )

  if oDoc:nStatus != HBXML_STATUS_OK
     cResponse := "Error While Processing File: " + AllTrim( Str( oDoc:nLine ) ) + " # "+;
                        "Error: " + HB_XmlErrorDesc( oDoc:nError ) + " # " +;
                        "Tag Error on tag: " + oDoc:oErrorNode:cName + " # " +;
                        "Tag Begin on line: " + AllTrim( Str( oDoc:oErrorNode:nBeginLine ) )
    RETURN cResponse
  endif

  oNode := oDoc:FindFirst( "NODE" )
  if oNode != NIL
    ?  oNode:GetAttribute( "ra" )   // Devuelve jose
  endif

 oDoc := NIL
 


En Harbour tienes que incluir la libreria de compatibilidad de xHarbour.
Saludos
Rafa Carmona ( rafa.thefullARROBAgmail.com___quitalineas__)
User avatar
thefull
 
Posts: 729
Joined: Fri Oct 07, 2005 7:42 am
Location: Barcelona


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 27 guests