Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple XML to VFP nightmare
Message
From
05/04/2019 22:58:42
 
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
01667970
Message ID:
01667992
Views:
59
>Hi
>I am trying to import into a VFP cursor a simple xml generated by Alpha Anywhere, with little to no success, using either xmltocursor or xmladapter.
>The XML string looks like this:
>
><?xml version="1.0" encoding="Windows-1255" standalone="yes"?>
><DOCUMENT>
>	<ROW>
>		<PatientID Type="N">1</PatientID>
>		<PatientName Type="C">Jaime</PatientName>
>		<SH Type="L">0</SH>
>		<Address Type="C">My Address</Address>
>		<City Type="C">Karkur/City>
>		<Zip Type="C">37512</Zip>
>		<HomePhone Type="C">037951010</HomePhone>
>		<Cell Type="C">0521234567</Cell>
>		<Birth Type="D">1973-02-22</Birth>
>		<VIP Type="N">0</VIP>
>	</ROW>
></DOCUMENT>
>
**ParseAlphaAnywhere.prg
**If your file is not too large, StrExtract() is very good at parsing xml 
lcContent = FileToStr("AlphaAnywhere.xml")
lnRows = OCCURS([<ROW>],lcContent)
FOR i = 1 TO lnRows
	&& parse each field as a string
	lcRow = StrExtract(lcContent,[<ROW>],[</ROW>],i)
	m.PatientID = STREXTRACT(lcRow,[<PatientID Type="N">],[</PatientID>])
	m.PatientName = STREXTRACT(lcRow,[<PatientName Type="C">],[</PatientName>])
	m.SH = STREXTRACT(lcRow,[<SH Type="L">],[</SH>])
	&& etc etc for all fields
	&& then convert the fields from strings into correct types
	m.PatientID = INT(VAL(m.PatientID))
	m.SH = IIF(m.SH = [0],.F.,.T.)
	INSERT INTO MyTable FROM memvar
ENDFOR 	
Previous
Reply
Map
View

Click here to load this message in the networking platform