problem with read from xml file

problem with read from xml file

Postby kajot » Mon Jan 16, 2017 9:35 pm

problem with read NUMER from xml file, I get empty NUMER

<NUMER>
<![CDATA[FA/1/12/2016/EXP]]>
</NUMER>

which means <![CDATA[
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby Antonio Linares » Thu Jan 19, 2017 8:25 am

How are you reading it ?

Please show the code
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42069
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: problem with read from xml file

Postby kajot » Thu Jan 19, 2017 9:55 pm

sc:=rtrim(init_mem)+'IMPORT'

cFileName := cGetFile( "XML File (*.Xml)|*.Xml|","Wybierz zbiór XML",sc)

If !file(cFileName)
break
Endif


mTekst:=""
@ 100,20 SAY oTEKST var mTekst OF oDlg PIXEL SIZE 150,12


dd:=day(date())
mm:=month(date())
rr:=year(date())

// hFile := FOpen( cFileName )

oXmlDoc := TXmlDocument():new() // HBXML_TYPE_CDATA HBXML_STYLE_NOESCAPE

oXmlDoc:read( Memoread( cFileName ) )
// oXmlDoc:read( hFile )
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby kajot » Sat Jan 21, 2017 5:22 pm

in FWH version 16.06 was ok
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby Enrico Maria Giordano » Sat Jan 21, 2017 5:32 pm

Please build a sample showing the problem that can be compiled and run here.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: problem with read from xml file

Postby kajot » Sun Jan 22, 2017 8:39 am

I send samples via mail
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby Enrico Maria Giordano » Sun Jan 22, 2017 11:09 am

Sorry, Thunderbird freezes when I try to open your message. I had to delete it.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: problem with read from xml file

Postby kajot » Sun Jan 22, 2017 11:52 am

I send You compressed
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby Enrico Maria Giordano » Sun Jan 22, 2017 5:36 pm

Sorry, I need a reduced sample. You have to take the time to reduce it at the smallest size yet showing the problem. And please reduce the file xml accordingly.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: problem with read from xml file

Postby kajot » Tue Jan 24, 2017 8:52 pm

my sample

t1.prg

//#include 'fivewin.ch'
#include 'hbxml.ch'

#define CRLF chr(13)+chr(10)

REQUEST DBFCDX
//------------------------------------------------------c---------------------//
function XML2RK()
local oDlg
local lSave := .f.
local oFont
local dd,mm,rr
LOCAL oXmlDoc,oXmlNode, oXmlRecScan, oXmlFieldScan

setpos(25,80)
cls

set_4_:=set(4,'yyyy-mm-dd')

begin sequence

cFileName := 'demo.xml'

If !file(cFileName)
break
Endif


cString:=Memoread( cFileName )
// cString:=strtran(cString,'<![CDATA[','')
// cString:=strtran(cString,']]>','')

oXmlDoc := TXmlDocument():new(,5) // ,HBXML_STYLE_NOESCAPE ) // HBXML_TYPE_CDATA HBXML_STYLE_NOESCAPE
if !( oXmlDoc:nError==HBXML_ERROR_NONE )
wait "xml file parsing error " + str(oXmlDoc:nError)
break
endif

oXMlDoc:read( cString )


oXmlNode00 := oXmlDoc:findFirst( "ROOT" )

oXmlRecScan0 := TXmlIteratorScan():new( oXmlNode00 )
oXmlNode0 := oXmlRecScan0:find( "REJESTRY_SPRZEDAZY_VAT" )

DO WHILE oXmlNode0 <> NIL
// oXmlFieldScan0 := TXmlIteratorScan():new( oXmlNode0 )

oXmlRecScan := TXmlIteratorScan():new( oXmlNode0 )
oXmlNode := oXmlRecScan:find( "REJESTR_SPRZEDAZY_VAT" )

DO WHILE oXmlNode <> NIL
tNUMER:=''
tDATA:=''
tNETTO:=''

oXmlFieldScan := TXmlIteratorScan():new( oXmlNode )

oXmlNode := oXmlFieldScan:find( "DATA" )
if oXmlNode#NIL
if oXmlNode:cData#NIL
tData:=oXmlNode:cData
endif
endif

oXmlNode := oXmlFieldScan:find( "NUMER" )
if oXmlNode#NIL
if oXmlNode:cData#NIL
tNUMER:=oXmlNode:cData
endif
endif

oXmlNode := oXmlFieldScan:find( "NETTO" )
if oXmlNode#NIL
if oXmlNode:cData#NIL
tNETTO:=oXmlNode:cData
endif
endif


alert('Data:'+tDATA+' '+'Numer:'+tNUMER+' '+'Netto:'+tNETTO)

oXmlNode := oXmlRecScan:next("REJESTR_SPRZEDAZY_VAT")

ENDDO
oXmlNode0 := oXmlRecScan0:next("REJESTRY_SPRZEDAZY_VAT")

ENDDO

end sequence

dbcloseall()
set(4,set_4_)


return
//------------------------------------------------------------------------------------//



demo.xml
-------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns="http://www.comarch.pl/cdn/optima/offline">
<REJESTRY_SPRZEDAZY_VAT>
<WERSJA>2.00</WERSJA>
<BAZA_ZRD_ID>SPRZE</BAZA_ZRD_ID>
<BAZA_DOC_ID>KSIEG</BAZA_DOC_ID>
<REJESTR_SPRZEDAZY_VAT>
<DATA>
<![CDATA[2016-12-01]]>
</DATA>
<NUMER>
<![CDATA[FA/1/12/2016/EXP]]>
</NUMER>
<NETTO>1400</NETTO>
</REJESTR_SPRZEDAZY_VAT>
</REJESTRY_SPRZEDAZY_VAT>
</ROOT>



t1.exe.xbp
-------------------------------------------------------------
CINI =
C_OUTPUTFOLDER =
DEFFILE =
INCLUDEFOLDERS =
LAUTORUN =
LDEBUG = .F.
LGUI = .F.
LIBFOLDERS =
LMT = .F.
LNOAUTOFWH = .F.
LPRG_CLASSICDEBUG = .F.
LPRG_DEBUG = .F.
LUSEDLL = .F.
MAPFILE =
MYC_FLAGS =
MYDEFINES =
MYLINK_FLAGS =
MYPRG_FLAGS =
MYRC_FLAGS =
MYSLY_FLAGS =
OUTPUTFOLDER =
PRG_OUTPUTFOLDER =
RC_OUTPUTFOLDER =
RUNARGUMENTS =
SLY_OUTPUTFOLDER =
STARTIN =
TARGETFOLDER =

[t1.prg]
MYC_FLAGS =
MYDEFINES =
MYPRG_FLAGS =
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland

Re: problem with read from xml file

Postby Enrico Maria Giordano » Tue Jan 24, 2017 10:10 pm

Using

Code: Select all  Expand view
oXmlNode:oChild:ToString()


at least you can read the string

Code: Select all  Expand view
<![CDATA[2016-12-01]]>


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: problem with read from xml file

Postby kajot » Wed Jan 25, 2017 7:55 pm

if so I do

tNUMER:=oXmlNode:oChild:ToString() //oXmlNode:cData

because I still getting empty tNumber
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland


Re: problem with read from xml file

Postby Enrico Maria Giordano » Wed Jan 25, 2017 8:38 pm

You have to replace this

Code: Select all  Expand view
if oXmlNode:cData#NIL


with this

Code: Select all  Expand view
if !Empty( oXmlNode:oChild:ToString() )


and extract the useful data from

Code: Select all  Expand view
oXmlNode:oChild:ToString()


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: problem with read from xml file

Postby cnavarro » Wed Jan 25, 2017 8:42 pm

kajot wrote:if so I do

tNUMER:=oXmlNode:oChild:ToString() //oXmlNode:cData

because I still getting empty tNumber


Are your variable names correct?

tNUMER or tNumber
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 95 guests