by Pedro Faro » Mon Jun 18, 2007 5: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 <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()