Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foxpro 2.6 and XML 1

Status
Not open for further replies.

Hicksie

Programmer
Jun 18, 2002
3
GB

Hi Peeps

I’m trying to see if I can read and writing XML strings via FoxPro 2.6, yes I am that mad!!!

Has anyone every come across any code / articles / techniques to help. Any help is sure to reduce my alcohol intake and prolong my life ( which I’m sure some people would prefer not to happen ;o)))) )

Cheers
 
Well, reading and writing XML is not difficult, after all they are just ASCII text files. You can use the low-level IO routines, for reading and writing, and even the standard text merge capabilities for writing them.

On the other hand, if you are asking about interpreting these files you'll have to write your own parser - the ones from MS that I know about are all 32-bit Windows based.

Any reason why you can't use the native VFP 7.0 xmltocursor() and cursortoxml() functions, or in 6.0/7.0 use the free "wwXML Class - exporting and importing XML for VFP
" at
Rick
 
dbf2xml can be found on the web as well (somewhere)

*-- ASCII codes
#DEFINE TAB CHR(9)
#DEFINE lf CHR(10)
#DEFINE cr CHR(13)
#DEFINE cr_lf cr+lf

* Dbf2xml.prg
*************************
* PROCEDURE dbf2xml


PARAMETERS tctable, tcscope, tntabindents
PRIVATE lctable, lcalias, lcscope, lcdbfname, lcindenttext, lcdbf, lcrootname
PRIVATE lcvalue, lcfield, lnfieldcount, lncount, lnlastselect, lnlastrecno
PRIVATE lcxmltext
DIMENSION lafields[1]

IF NOT INLIST(TYPE('tctable'), "C", "L") OR NOT ;
INLIST(TYPE('tcscope'), "C", "L")
RETURN ""
ENDIF

lcindenttext = IIF(TYPE('tntabindents') == "N", ;
REPLICATE(TAB, tntabindents), "")
lctable = LOWER(IIF(EMPTY(tctable), ALIAS(), ALLTRIM(tctable)))
lnlastselect=SELECT()

IF "." $ lctable
lcdbf = lctable
IF NOT FILE(lcdbf)
RETURN ""
ENDIF

SELECT 0
lcalias = LOWER(SYS(2015))
USE (lcdbf) ALIAS (lcalias) AGAIN shared
lcdbfname = LOWER(forceext(justfname(DBF()), ""))
ELSE
lcdbf = ""
lcalias = lctable
lcdbfname = lcalias
ENDIF

IF NOT USED(lcalias)
SELECT (lnlastselect)
RETURN ""
ENDIF

lcscope = IIF(EMPTY(tcscope), "ALL", ALLTRIM(tcscope))

SELECT (lcalias)

lnlastrecno = IIF(EOF(), 0, RECNO())
lcxmltext = &quot;<&quot;+ lcdbfname + &quot;_table>&quot; + cr_lf

lnfieldcount = AFIELDS(lafields)
IF lnfieldcount = 0
SELECT (lnlastselect)
RETURN &quot;&quot;
ENDIF

lcrootname = lcdbfname
DO WHILE TYPE(lcrootname) != &quot;U&quot;
lcrootname = lcrootname + &quot;1&quot;
ENDDO

SCAN
lcxmltext = lcxmltext + lcindenttext + ;
&quot;<&quot; + lcrootname + &quot;>&quot; + cr_lf

FOR lncount = 1 TO lnfieldcount
lcfield = LOWER(lafields[lnCount, 1])

lcvalue = EVALUATE(lcfield)
lcvalue = std_tran(lcvalue)
IF EMPTY(lcvalue)
LOOP
ENDIF

lcxmltext=lcxmltext + lcindenttext + TAB + ;
&quot;<&quot; + lcfield + &quot;>&quot; + lcvalue + &quot;</&quot; + lcfield + &quot;>&quot; + cr_lf
ENDFOR

lcxmltext = lcxmltext + lcindenttext + ;
&quot;</&quot; + lcrootname + &quot;>&quot; + cr_lf
ENDSCAN

IF EMPTY(lcdbf)
IF lnlastrecno > 0
GO lnlastrecno
ENDIF
ELSE
USE
ENDIF

SELECT (lnlastselect)

lcxmltext = lcxmltext + cr_lf + &quot;</&quot;+ lcdbfname + &quot;_table>&quot;

RETURN lcxmltext
 
Hi Gents,

Thanks for your replies.

RGBean, I've found the wwXML code and if I could would much prefer to use that and VFP6/7. However, I'm dealing with a legacy system so I can't convert (or should I say the company won't cover the cost of converting) the system to VFP.

DWD68071, Thanks for the code, looks good and should help me greatly. If I could buy you a pint I would.

Cheers
Happy H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top