FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour problem with read from xml file
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
problem with read from xml file
Posted: Mon Jan 16, 2017 09: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: problem with read from xml file
Posted: Thu Jan 19, 2017 08:25 AM

How are you reading it ?

Please show the code

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Thu Jan 19, 2017 09:55 PM

sc:=rtrim(init_mem)+'IMPORT'

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

If !file(cFileName)
break
Endif


mTekst:=&quot;&quot;     
@ 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
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Sat Jan 21, 2017 05:22 PM

in FWH version 16.06 was ok

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Sat Jan 21, 2017 05:32 PM

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

EMG

Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Sun Jan 22, 2017 08:39 AM

I send samples via mail

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Sun Jan 22, 2017 11:09 AM

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

EMG

Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Sun Jan 22, 2017 11:52 AM

I send You compressed

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Sun Jan 22, 2017 05: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
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Tue Jan 24, 2017 08: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 &quot;xml file parsing error &quot; + str(oXmlDoc:nError)
      break
   endif

  oXMlDoc:read( cString )


  oXmlNode00 := oXmlDoc:findFirst( &quot;ROOT&quot; )

  oXmlRecScan0 := TXmlIteratorScan():new( oXmlNode00 )
  oXmlNode0    := oXmlRecScan0:find( &quot;REJESTRY_SPRZEDAZY_VAT&quot; )

  DO WHILE oXmlNode0 &lt;&gt; NIL

// oXmlFieldScan0 := TXmlIteratorScan():new( oXmlNode0 )

    oXmlRecScan := TXmlIteratorScan():new( oXmlNode0 )
    oXmlNode    := oXmlRecScan:find( &quot;REJESTR_SPRZEDAZY_VAT&quot; )

    DO WHILE oXmlNode &lt;&gt; NIL
       tNUMER:=''
       tDATA:=''
       tNETTO:=''

       oXmlFieldScan := TXmlIteratorScan():new( oXmlNode )

       oXmlNode      := oXmlFieldScan:find( &quot;DATA&quot; )         
       if oXmlNode#NIL                  
          if oXmlNode:cData#NIL         
             tData:=oXmlNode:cData
          endif   
       endif

       oXmlNode      := oXmlFieldScan:find( &quot;NUMER&quot; )         
       if oXmlNode#NIL                  
          if oXmlNode:cData#NIL         
             tNUMER:=oXmlNode:cData
          endif   
       endif

       oXmlNode      := oXmlFieldScan:find( &quot;NETTO&quot; )         
       if oXmlNode#NIL                  
          if oXmlNode:cData#NIL         
             tNETTO:=oXmlNode:cData
          endif   
       endif


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

      oXmlNode := oXmlRecScan:next(&quot;REJESTR_SPRZEDAZY_VAT&quot;)

  ENDDO       
  oXmlNode0 := oXmlRecScan0:next(&quot;REJESTRY_SPRZEDAZY_VAT&quot;)

  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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Tue Jan 24, 2017 10:10 PM
Using

Code (fw): Select all Collapse
oXmlNode:oChild:ToString()


at least you can read the string

Code (fw): Select all Collapse
<![CDATA[2016-12-01]]>


EMG
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: problem with read from xml file
Posted: Wed Jan 25, 2017 07:55 PM

if so I do

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

because I still getting empty tNumber

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Wed Jan 25, 2017 08:33 PM

Works fine here.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: problem with read from xml file
Posted: Wed Jan 25, 2017 08:38 PM
You have to replace this

Code (fw): Select all Collapse
if oXmlNode:cData#NIL


with this

Code (fw): Select all Collapse
if !Empty( oXmlNode:oChild:ToString() )


and extract the useful data from

Code (fw): Select all Collapse
oXmlNode:oChild:ToString()


EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: problem with read from xml file
Posted: Wed Jan 25, 2017 08:42 PM
kajot wrote:if so I do

tNUMER:=oXmlNode: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