I have a problem reading xml file size 10 MB
I got memory error
LOCAL vXML, oText, TempText, aText, cXML
cXML := cDirPleno + "\" + ALLTRIM( "REMESSA\PROTOCOLOS\" ) + ;
ALLTRIM( ( cAlias )->CHAVE ) + ;
"-CCe"+ALLTRIM(STR( ( cAlias )->CODI ) ) + ".xml"
IF .NOT. FILE( cXML )
// MENS
ENDIF
vXML := cXML
oText = TTxtFile():New( vXML ) // Read Mode
oText:nMaxLineLength := 5120
TempText = oText:ReadLine()
kajot wrote:https://mega.nz/file/xeFx3SCS#LOZWjmZzyMM1HZ61g7OwNTYYUhUFfmgGhpYocPbbtTk
best regards
kajot
#include "FiveWin.ch"
Static aValues := {}
function Main()
XmlTree( "JPK_FAKTURA_22-06-2023.xml" )
XBrowse( aValues )
return nil
//----------------------------------------------------------------------------//
static function XmlTree( cXml )
local oXmlDoc
local oRoot
local cPrompt
local cData
local oTree
TRY
oXmlDoc := TXmlDocument():New( cXml )
CATCH
? "TXmlDocument class can not read " + cXml
return nil
END
oRoot := oXmlDoc:oRoot
cPrompt := If( Empty( oRoot:cName ), cFileNoPath( cXml ), oRoot:cName )
cData := if( Empty( oRoot:cData ), "Empty Value", oRoot:cData )
AAdd( aValues, { cPrompt, cData, oRoot:oChild, oRoot:oNext, oRoot:oPrev, oRoot:oParent, oRoot:Path() } )
if !Hb_IsNil( oRoot:oChild )
SubTree( oRoot:oChild )
endif
return nil
static function SubTree( oNode )
local cPrompt
local cData
do while oNode != nil
if !Empty( oNode:aAttributes ) //Valtype( oNode:aAttributes ) = "H"
HEVal( oNode:aAttributes, { | cKey, cValue | AAdd( aValues, { cKey, cValue, , , , , oNode:Path()} ) } )
endif
cPrompt := If( Empty( oNode:cName ), "", oNode:cName )
cData := if( Empty( oNode:cData ), "Empty Value", oNode:cData )
AAdd( aValues, { cPrompt, cData, oNode:oChild, oNode:oNext, oNode:oPrev, oNode:oParent, oNode:Path() } )
if !Hb_IsNil( oNode:oChild )
SubTree( oNode:oChild )
endif
oNode := oNode:oNext
enddo
return nil
kajot wrote:How can I use
oText:ReadLine()
with
TXmlDocument():New( )
KAJOT
// C:\FWH\SAMPLES\KAJOTXML.PRG
#include "FiveWin.ch"
FUNCTION Main()
// LOCAL oText := TTxtFile():New( "leandro.xml" ) // only test
LOCAL oText := TTxtFile():New( "FAKTURA.xml" ) // KAJOT
LOCAL n, cText := ""
LOCAL cImptxt, cTexto, oPrn, oFont, nLin, nLinha
IF( .NOT. oText:Open() )
? "impossible Open"
oText:Close()
QUIT
ENDIF
// number max. lines.
oText:nMaxLineLength := 350000 // KAJOT - Look this.
oText:RecCount()
// ONLY TEST
// FOR n = 1 TO 5120
FOR n = 1 TO 330000 // FACTURA.XML -> 326.642 lines. KAJOT
oText:ReadLine()
cText += oText:ReadLine()
oText:Skip()
NEXT
cTexto := ALLTRIM( cText )
// ? cTexto
PRINTER oPrn NAME "Imprimindo um TXT" PREVIEW MODAL
DEFINE FONT oFont NAME "COURIER NEW" SIZE 0, - 8 OF oPrn
oPrn:SetPage( 9 ) // A4
oPrn:SetPortrait() // Vertical
PAGE
nLin := 1
FOR nLinha = 1 TO MLCOUNT( cTexto, 100 )
SYSREFRESH()
oPrn:CmSay( nLin := nLin + .4, 1.5, MEMOLINE( cTexto, 100, nLinha ), oFont )
IF nLin > 25
nLin := 1
ENDPAGE
PAGE
ENDIF
NEXT
ENDPAGE
ENDPRINT
oFont:End()
oText:Close()
RETURN NIL
// FIN / END
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 60 guests