Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create a cursor from an XML file
Message
From
02/01/2017 01:28:43
 
 
To
01/01/2017 19:19:27
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01646245
Message ID:
01646251
Views:
82
Likes (2)
>>>Hi.. Happy New Year!
>>>
>>>Is it possible (and if yes, how?) to create a cursor (of course, at run time) from a structure defined in an XML file included in the application EXE? What would the XML look like?
>>
>>Have you looked at the VFP XMLTOCURSOR() function? If not, Googling [VFP XMLTOCURSOR] should get you started.
>
>I have used this function many times but forgot. And I was actually hoping that I will be able to store structures of multiple (different) tables in one XML file and pass a parameter to use a subset of the XML. But if this is not possible, I will have several XML files.
>Thank you very much.

Actually, you can. You'll just have to identify, for XMLCURSOR(), what part of the XML you want to use.
LOCAL XMLSourceData AS String
LOCAL XML AS MSXML2.DOMDocument60

TEXT TO m.XMLSourceData NOSHOW FLAGS 1
<?xml version="1.0" encoding="windows-1252"?>
<sourceData>
	<table name="persons">
		<person>
			<name>John</name>
			<gender>M</gender>
			<born>1997-06-05</born>
		</person>
		<person>
			<name>Mary</name>
			<gender>F</gender>
			<born>1995-12-23</born>
		</person>
	</table>
	<table name="cars">
		<car>
			<brand>Rover</brand>
			<model>75</model>
			<year>2005</year>
		</car>
		<car>
			<brand>Renault</brand>
			<model>Mégane</model>
			<year>1997</year>
		</car>
	</table>
</sourceData>
ENDTEXT

m.XML = CREATEOBJECT("MSXML2.DOMDocument.6.0")

m.XML.LoadXML(m.XMLSourceData)

XMLTOCURSOR(m.XML.Selectnodes("/sourceData/table[@name='persons']").item(0).xml, "Persons")

XMLTOCURSOR(m.XML.Selectnodes("/sourceData/table[@name='cars']").item(0).xml, "Cars")

SELECT Persons
BROWSE NOWAIT

SELECT Cars
BROWSE NOWAIT
MOVE WINDOW Cars BY 5,10
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform