XML

Post Reply
User avatar
Pedro Faro
Posts: 31
Joined: Sun Jan 29, 2006 6:34 pm
Location: Lisboa-Portugal
Contact:

XML

Post by Pedro Faro »

Hi

I need to create a xml File and someone as changed the xml.prg to work with xh.

In my code I have this sample:

Function TesteXML()

Local oXml

XML oXml FILE "TESTE.XML" FORMATED


only with this line it returns:

Descrição do erro: Error BASE/1004 Class: 'ARRAY' has no exported method: NEW
Args:
[ 1] = C TESTE.XML
[ 2] = U TESTE.XML
[ 3] = U TESTE.XML
[ 4] = U TESTE.XML
[ 5] = L TESTE.XML

Stack Calls
===========
Called from NEW(0)
Called from TESTEXML(5296)

Can anybody help me about this error.

best regards
Pedro
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Pedro,

Are you using xHarbour and its Class TXml ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Pedro Faro
Posts: 31
Joined: Sun Jan 29, 2006 6:34 pm
Location: Lisboa-Portugal
Contact:

Post by Pedro Faro »

Hi Antonio

I use:

xHarbour build 0.99.41

FWHX 2.6 May 2005

use also class xml.prg with a xml.ch (example below..)

*******************************************************************************
* Pruebas para la creacion de fichero xml desde fivewin *
* 01 - 05 - 2002 *
* Enviarme vuestras dudas y sugerencias a fredy@airtel.net *
*******************************************************************************

#include "hbclass.ch"
#include "fileio.ch"
#include "common.ch "

CLASS TXMLWRITE

DATA hFile, lFormated, CRLF, aMark

METHOD New( cOut, cVer, cEncode, cSheet, lFormated ) CONSTRUCTOR

METHOD Open( cMark, cType, aAttrib, cTag, lClose, cExt )
METHOD End() INLINE FClose( ::hFile )
METHOD Procesar( cText )
METHOD Close()

END

This class works great in FW (without the modifications of default ..)

best regards
Pedro
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Pedro,

Please post the source code of METHOD New( cOut, cVer, cEncode, cSheet, lFormated ) CONSTRUCTOR
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Pedro Faro
Posts: 31
Joined: Sun Jan 29, 2006 6:34 pm
Location: Lisboa-Portugal
Contact:

Post by Pedro Faro »

Antonio

below the xml.prg and the xml.ch.
As i said, someone adapted the FW to Xh/FWH class that i got in this newsgroup.


regards
Pedro



xml.prg:

#include "hbclass.ch"
#include "fileio.ch"
#include "common.ch "

CLASS TXMLWRITE

DATA hFile, lFormated, CRLF, aMark

METHOD New( cOut, cVer, cEncode, cSheet, lFormated ) CONSTRUCTOR

METHOD Open( cMark, cType, aAttrib, cTag, lClose, cExt )
METHOD End() INLINE FClose( ::hFile )
METHOD Procesar( cText )
METHOD Close()

END

//----------------------------------------------------------------------------//

METHOD New( cOut, cVer, cEncode, cSheet, lFormated ) CLASS TXMLWRITE

DEFAULT cVer TO "1.0"
DEFAULT cEncode TO "ISO-8859-1"

//BYNAME lFormated

::CRLF := If( lFormated, Chr(13)+Chr(10), "" )
::aMark := {}

::hFile := FCreate( AllTrim( cOut ), 0 )
::Procesar( '<?xml version="' + cVer + '" encoding="' + cEncode + '"?>' )

IF !Empty( cSheet )
::Procesar( '<?xml-stylesheet href="'+ AllTrim( cSheet ) + '" Type="text/xsl"?>' )
END IF

RETURN Self


METHOD Open ( cMark, cType, aAttrib, cTag, lClose, cExt ) CLASS TXMLWRITE
Local n, cBuffer

DEFAULT cTag TO ""
DEFAULT cType TO ""
DEFAULT cExt TO ""

aAdd( ::aMark, cMark )

cBuffer := '<' + cMark

IF Len( ::aMark ) == 1
cBuffer += ' xmlns:dt="urn:schemas-microsoft-com:datatypes"'
END IF

IF !Empty( cType )
cBuffer += ' dt:dt= "' + cType + '"'
END IF

IF Len( aAttrib ) > 0
FOR n := 1 TO Len( aAttrib )
cBuffer += ' '+ aAttrib[n,1] + ' = "' + aAttrib[n,2] + '" '
NEXT
END IF

cBuffer += '>' + cTag + If( lClose, '</' + cMark + '>' , "" )
::Procesar( cBuffer )

IF lClose
aSize( ::aMark, Len( ::aMark ) -1 )
END IF

RETURN NIL

METHOD Close CLASS TXMLWRITE

::Procesar( "</" + ::aMark[ Len( ::aMark ) ] + ">" )
aSize( ::aMark, Len( ::aMark ) -1 )

RETURN NIL

METHOD Procesar( cBuffer ) CLASS TXMLWRITE

Local nSpaces := If( ::lFormated, Len( ::aMark ), 0 )

cBuffer := Space( nSpaces )+ cBuffer + ::CRLF
FWrite( ::hFile, cBuffer, Len( cBuffer ) )

RETURN NIL

xml.ch:

#xcommand XML <oXml> FILE <cOut> ;
[ VERSION <cVer> ] ;
[ ENCODING <cEncode> ] ;
[ STYLESHEET <cSheet> ] ;
[ <lFormated:FORMATED> ];
=> ;
<oXml> := TXmlWrite():New( <cOut>, <cVer>, <cEncode>, <cSheet>, <.lFormated.> )

#xcommand XML OPEN MARK <cMark> [ TYPE <cType> ] ;
[ ATTRIB <cAttrib1> VALUE <uVal1> ;
[ ATTRIB <cAttrib2> VALUE <uValN> ]] ;
[ EXTENDED <uExt> ] ;
[ TAG <cTag> ] ;
[ <lAutoClose:AUTOCLOSE> ];
<of: OF> <oXml> ;
=> ;
<oXml>:Open( <cMark>, <cType>,;
{ [ { <cAttrib1> ,<uVal1> } ] [, { <(cAttrib2)> ,<(uValN)>} ] },;
<cTag>, <.lAutoClose.>, <uExt>)

#xcommand XML CLOSE MARK <of: OF> <oXml> ;
=> ;
<oXml>:Close( )

#xcommand XML END <oXml> ;
=> ;
<oXml>:End()
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Pedro,

Your code is working fine here using FWH 7.05 and Harbour/xharbour.

We just changed END into ENDCLASS and added ::lFormated := lFormated to Method New()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Pedro Faro
Posts: 31
Joined: Sun Jan 29, 2006 6:34 pm
Location: Lisboa-Portugal
Contact:

Post by Pedro Faro »

Antonio

Thanks very much

I never guess that it was so easyer.

best regards

Pedro Faro
Post Reply