FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Leer variables de un fichero XLM
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Leer variables de un fichero XLM
Posted: Sun Jan 24, 2010 07:07 PM

Necesito leer unas variables que me entregan en un fichero en formato XLM.
Existe alguna funci贸n para realizarlo.

Posts: 610
Joined: Wed Oct 19, 2005 08:20 PM
Re: Leer variables de un fichero XLM
Posted: Sun Jan 24, 2010 08: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
Posts: 731
Joined: Fri Oct 07, 2005 07:42 AM
Re: Leer variables de un fichero XLM
Posted: Mon Jan 25, 2010 01: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 (fw): Select all Collapse
#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__)

Continue the discussion