Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP com object advice
Message
From
31/08/2006 08:13:14
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
 
 
To
30/08/2006 15:20:24
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01149918
Message ID:
01150101
Views:
29
David,

Thank you, this was very helpful.

Jerry


>Jerry,
>
>>We would like to have any sort of developer use our COM object. What is the best way of passing the data back to a developer who is using our COM object?
>
>XML is the way to go, but you should try to keep the size of the data sets as small as possible (only pass back the records and fields really needed). Supposing you have a method that queries up a set of records into a cursor called MyCursor, you could get the data into XML as easily as this:
LOCAL lcxml
>CURSORTOXML("MyCursor", "lcxml", 1, 2, 0, "1")
>RETURN lcxml
The 6th parameter "1" means you want an inline schema embedded into the file, which will provide anyone using the XML with the specs about data types, lengths and precision. If you don't want the overhead of carrying that schema back with every hit, you can provide an external schema to the consumers as the spec for your result XML and remove the 6th param (default is no schema) to send just the data with each request.
>
>To initially create an external schema to provide them, you can set the 6th parameter to "MyCursor.xsd", which will create a schema all over again on each hit and will place a reference to the external schema into the XML. However, after you have done that just once and have the external schema, you can make the 6th param "" so it won't create the schema every time, and set the optional 7th param (schemalocation) to "MyCursor.xsd" to get a ref to the schema in the XML or leave off the 6th and 7th params to get no reference at all added into the XML. (If you add a reference to the XSD in the XML, it means that the consumer of your XML will be looking for that XSD as it loads and parses the XML you provide. They can still use an external XSD without having it referenced in the XML by specifying it explicitly in their code, but the reference in the XML means that most parsers will automatically read in the referenced schema if it exists.)
>
>NOTE: The name of the XSD is not important -- it does not have to correspond to the name of the XML file or cursor (in this case you're not passing back a file anyway, but just the XML text itself).
>
>I set the 4th parameter to a flag value of 2, which means to surround empty fields with both a beginning and ending tag instead of a single tag with a /> ending. This is to make sure any XML consumer can read it OK. If you have another spec you need to support, you can configure many aspects, such as setting encoding to UTF-8 with other flag settings that can be added together as needed to configure your result.
>
>NOTE: Just the first two params are required if the defaults are OK for you.
>
>If you need to further customize the output, such as changing the root tag from VFPData to something else or changing the tag names for certain fields, you can either STRTRAN the result or use XMLAdapter instead (it has more options for customizing the output). You also might want to use XMLAdapter if you need to include more than one cursor/table in the XML. If you want to know how to do these things with XMLAdapter, search my messages here or attend my XMLAdapter session at FoxForward conference mid-September in Atlanta (http://foxforward.net).
Previous
Reply
Map
View

Click here to load this message in the networking platform