Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML File from several Cursors with 1 cursor without rela
Message
From
01/05/2019 15:49:47
 
 
To
01/05/2019 15:21:17
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01668303
Message ID:
01668341
Views:
49
>>Hello community,
>>
>>I have found this example to generate XML file With associated XSD, but i want create the same example using another cursor that as no Key to associate to tables customers and Orders and OrdersDetails, like on the example:
>>
>>Select customers
>>Set Relation To customerid Into crsOrders In crsCustomer
>>Set Relation To orderid Into crsOrdDet In crsOrders Additive
>>
>>In this case how can do that?, for example i use on example above the table Territories (Suppose this table contains my enterprise data informations), i don´t have any field to create relation between the other tables ?
>>Also, i need my company information on the main TAG like :
>>
>><Enterprise>
>>    <territoryid>02116</territoryid>
>>    <territorydescription>Boston</territorydescription>
>>    <regionid>1</regionid>
>>	<MyCustomer>
>>		<customerid>BONAP</customerid>
>>		<companyname>Bon app'</companyname>
>>		<contactname>Laurence Lebihan</contactname>
>>		<contacttitle>Owner</contacttitle>
>>		<address>12, rue des Bouchers</address>
>>		<city>Marseille</city>
>>		<postalcode>13008</postalcode>
>>		<country>France</country>
>>		<phone>91.24.45.40</phone>
>>		<fax>91.24.45.41</fax>
>>		<MyOrders>
>>			<orderid>10331</orderid>
>>			<customerid>BONAP</customerid>
>>			<employeeid>9</employeeid>
>>			<orderdate>1996-10-16</orderdate>
>>			<requireddate>1996-11-27</requireddate>
>>			<shippeddate>1996-10-21</shippeddate>
>>			<shipvia>1</shipvia>
>>			<freight>10.1900</freight>
>>			<shipname>Bon app'</shipname>
>>			<shipaddress>12, rue des Bouchers</shipaddress>
>>			<shipcity>Marseille</shipcity>
>>			<shippostalcode>13008</shippostalcode>
>>			<shipcountry>France</shipcountry>
>>			<MyOrderDetails>
>>				<orderid>10331</orderid>
>>				<productid>54</productid>
>>				<unitprice>5.9000</unitprice>
>>				<quantity>15</quantity>
>>				<discount>0.00000</discount>
>>			</MyOrderDetails>
>>		</MyOrders>
>></Enterprise>
>>
>>Finally, if i want to remove from the XML file the XSD content , how can do that ?
>>
>>The code i use to produce the XML and XSD file is:
>>
>>CLOSE DATABASES ALL
>>OPEN DATABASE (HOME() + [samples\northwind\northwind])
>>
>>USE territories IN 0
>>USE customers IN 0
>>USE orders IN 0
>>USE OrderDetails IN 0
>>
>>SELECT * ;
>>	FROM territories ;
>>	WHERE territoryid = '02116' ;
>>	into cursor crsTerritory
>>	
>>
>>Select customers.* ;
>>  from customers ;
>>  where customerid = 'BONAP' ;
>>  into Cursor crsCustomer nofilter
>>
>>Select t1.* ;
>>  from orders t1 ;
>>  inner Join crsCustomer t2 On t1.customerid = t2.customerid ;
>>  into Cursor crsOrders nofilter
>>Index On customerid Tag customerid
>>
>>Select t1.* ;
>>  from OrderDetails t1 ;
>>  inner Join crsOrders t2 On t1.orderid = t2.orderid ;
>>  into Cursor crsOrdDet nofilter
>>Index On orderid Tag orderid
>>
>>SELECT territories
>>*set fields TO territorydescription
>>
>>Select customers
>>*SET RELATION TO territorydescription INTO crsOrders In crsCustomer
>>Set Relation To customerid Into crsOrders In crsCustomer
>>Set Relation To orderid Into crsOrdDet In crsOrders Additive
>>
>>Local loAdapter As Xmladapter ,loAdapter2 As Xmladapter
>>loAdapter = Createobject('XMLAdapter')
>>loAdapter.AddTableSchema('crsTerritory',.T.,Strconv('Enterprise',12))
>>loAdapter.AddTableSchema('crsCustomer',.T.,Strconv('MyCustomer',12))
>>loAdapter.AddTableSchema('crsOrders',  .T.,Strconv('MyOrders',12),'','',.F.,.F.,.T.)
>>loAdapter.AddTableSchema('crsOrdDet',  .T.,Strconv('MyOrderDetails',12),'','',.F.,.F.,.T.)
>>loAdapter.RespectNesting = .T.
>>loAdapter.ToXML('cMyData','',.T.)
>>MODIFY FILE cMyData.xml
>>
>>
>>Many thanks,
>>Best regards,
>>Luis
>
>Hi Luis, check code comments:
>
>
>Close Databases All
>Open Database (Home() + [samples\northwind\northwind])
>
>Use territories In 0
>Use customers In 0
>Use orders In 0
>Use OrderDetails In 0
>
>Select * ;
>	FROM territories ;
>	WHERE territoryid = '02116'  ;
>	into Cursor crsTerritory
>
>
>Select customers.* ;
>	from customers ;
>	where customerid = 'BONAP' ;
>	into Cursor crsCustomer nofilter
>
>
>Select t1.* ;
>	from orders t1 ;
>	inner Join crsCustomer t2 On t1.customerid = t2.customerid ;
>	into Cursor crsOrders nofilter
>Index On customerid Tag customerid
>
>Select t1.* ;
>	from OrderDetails t1 ;
>	inner Join crsOrders t2 On t1.orderid = t2.orderid ;
>	into Cursor crsOrdDet nofilter
>Index On orderid Tag orderid
>
>Set Relation To customerid Into crsOrders In crsCustomer
>Set Relation To orderid Into crsOrdDet In crsOrders
>
>*******************************************************************
>Select crsCustomer
>Index On customerid Tag customerid
>Set Relation to '' Into crsCustomer In crsTerritory && cheat 1:1 relation
>********************************************************************
>
>loAdapter = Createobject('XMLAdapter')
>
>With loAdapter As Xmladapter
>
>************************************************************************
>	.XMLName = strconv('XML',12) && change root <VFPDATA> TO <XML>
>	.XMLSchemaLocation = '' && supress XSD
>	.RespectNesting = .T.  && set this default BEFORE adding tables, then no need to specify for each table
>************************************************************************
>
>	.AddTableSchema('crsTerritory',.T.,Strconv('Enterprise',12))
>	.AddTableSchema('crsCustomer',.T.,Strconv('MyCustomer',12))
>	.AddTableSchema('crsOrders',  .T.,Strconv('MyOrders',12))
>	.AddTableSchema('crsOrdDet',  .T.,Strconv('MyOrderDetails',12))
>	.ToXML('cMyData','',.T.)
>
>Endwith
>
>Modify File cMyData.XML
>
>
>
>
>Hello Marco,
>
>Many thanks for your reply and comments, i will go to test it.
>
>Best regards,
>Luis
>
>Hello Marco,
>
>Sorry i forget to ask the following, how could i supress Tag OrderId on Node MyOrderDetails without loosing the relation between cursors.
>I ask this because sometimes that could be necessary, i see another post where use :
>Select customers
>SET FIELDS TO (Selection of some fields from cursor)
>
>Using the example that you send to me and work like a charm, can i do that ?
>
>like that :
>
><?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
><XML>
>	<Enterprise>
>		<territoryid>02116</territoryid>
>		<territorydescription>Boston</territorydescription>
>		<regionid>1</regionid>
>		<MyCustomer>
>			<customerid>BONAP</customerid>
>			<companyname>Bon app'</companyname>
>			<contactname>Laurence Lebihan</contactname>
>			<contacttitle>Owner</contacttitle>
>			<address>12, rue des Bouchers</address>
>			<city>Marseille</city>
>			<postalcode>13008</postalcode>
>			<country>France</country>
>			<phone>91.24.45.40</phone>
>			<fax>91.24.45.41</fax>
>			<MyOrders>
>				<orderid>10331</orderid>
>				<customerid>BONAP</customerid>
>				<employeeid>9</employeeid>
>				<orderdate>1996-10-16</orderdate>
>				<requireddate>1996-11-27</requireddate>
>				<shippeddate>1996-10-21</shippeddate>
>				<shipvia>1</shipvia>
>				<freight>10.1900</freight>
>				<shipname>Bon app'</shipname>
>				<shipaddress>12, rue des Bouchers</shipaddress>
>				<shipcity>Marseille</shipcity>
>				<shippostalcode>13008</shippostalcode>
>				<shipcountry>France</shipcountry>
>				<MyOrderDetails>
>					<orderid>10331</orderid>  && is possible to remove this TAG
>					<productid>54</productid>
>					<unitprice>5.9000</unitprice>
>					<quantity>15</quantity>
>					<discount>0.00000</discount>
>				</MyOrderDetails>
>			</MyOrders>
>	</Enterprise>
></XML>
>
>
>
>Thanks again,
>Best regards,
>Luis

Hi Luis, no.. the set relation to "" is just a trick that works safely if you have a cursor
with just 1 record on the left side of the relation. VFP has to include the correlated
colums so the consumer can establish the relation again on parsed cursors from xml.
@nfoxdev
github.com/nfoxdev
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform