FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour XML
Posts: 31
Joined: Sun Jan 29, 2006 06:34 PM
XML
Posted: Mon Jun 18, 2007 02:59 PM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
XML
Posted: Mon Jun 18, 2007 03:24 PM

Pedro,

Are you using xHarbour and its Class TXml ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 31
Joined: Sun Jan 29, 2006 06:34 PM
XML
Posted: Mon Jun 18, 2007 04:40 PM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
XML
Posted: Mon Jun 18, 2007 05:04 PM

Pedro,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 31
Joined: Sun Jan 29, 2006 06:34 PM
XML
Posted: Mon Jun 18, 2007 05:34 PM

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  &lt;cVer&gt; ] ;
                   [ ENCODING &lt;cEncode&gt; ] ;
                   [ STYLESHEET &lt;cSheet&gt; ] ;
                   [ &lt;lFormated:FORMATED&gt; ];
   =&gt; ;
      &lt;oXml&gt; := TXmlWrite():New( &lt;cOut&gt;, &lt;cVer&gt;, &lt;cEncode&gt;, &lt;cSheet&gt;, &lt;.lFormated.&gt; )

xcommand XML OPEN MARK <cMark> [ TYPE <cType> ] ;

                   [ ATTRIB &lt;cAttrib1&gt; VALUE &lt;uVal1&gt;  ;
                   [ ATTRIB &lt;cAttrib2&gt; VALUE &lt;uValN&gt; ]] ;
                   [ EXTENDED &lt;uExt&gt; ] ;
                   [ TAG &lt;cTag&gt; ] ;
                   [ &lt;lAutoClose:AUTOCLOSE&gt; ];
                    &lt;of: OF&gt; &lt;oXml&gt;  ;
   =&gt; ;
       &lt;oXml&gt;:Open( &lt;cMark&gt;, &lt;cType&gt;,;
        {   [  { &lt;cAttrib1&gt; ,&lt;uVal1&gt; } ]  [, { &lt;(cAttrib2)&gt; ,&lt;(uValN)&gt;} ]  },;
        &lt;cTag&gt;, &lt;.lAutoClose.&gt;, &lt;uExt&gt;)

xcommand XML CLOSE MARK <of: OF> <oXml> ;

   =&gt; ;
       &lt;oXml&gt;:Close(  )

xcommand XML END <oXml> ;

   =&gt; ;
       &lt;oXml&gt;:End()
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
XML
Posted: Mon Jun 18, 2007 05:59 PM

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
Posts: 31
Joined: Sun Jan 29, 2006 06:34 PM
XML
Posted: Mon Jun 18, 2007 07:11 PM

Antonio

Thanks very much

I never guess that it was so easyer.

best regards

                    Pedro Faro

Continue the discussion