As I worked on the slides for an upcoming talk on .NET webservices, I developed a few examples to go along with the talk. It was easy to put together web service consumers in C#, but Visual FoxPro wasn’t so easy (for me), since I hadn’t done professional FoxPro development in many years. But I had to get a FoxPro example out, since the talk is being sponsored by a Visual FoxPro user group. As usual, I checked Google, but I wasn’t encouraged by what I found.

So, I pulled the XML-serialized data set into a text file and started mercilessly chopping away at it until I had something I could feed into Visual FoxPro’s XMLTOCURSOR() function.

When I get the data set back from the .NET web service, it looks roughly like this:

<DataSet> ...
  <xs:schema> ... </xs:schema>
  <diffgr:diffgram> ...
    <NewDataSet> ... </NewDataSet>
  </diffgr:diffgram>
</DataSet>

I figured out that what I wanted was the <NewDataSet> element and everything it contained. The only problem is that some of the elements in it contain references to outer namespaces, as in:

<Authors diffgr:id="Authors2" msdata:rowOrder="1">

By stripping these out, I ended up with something I could feed into XMLTOCURSOR() and browse (see Figure 1). Here is the listing for my Visual FoxPro program:

LOCAL oWS AS ADOTest
********************************************
* IntelliSense-generated code appears here *
********************************************

LOCAL dotnetDS as String
LOCAL vfpDS as String
LOCAL dsrows as String

* Get the .NET Data set. It looks like:
*   <DataSet> ...
*     <xs:schema> ... </xs:schema>
*     <diffgr:diffgram> ...
*       <NewDataSet> ... </NewDataSet>
*     </diffgr:diffgram>
*   </DataSet>
*
* We want the NewDataSet, since it contains the rows.
*
dotnetDS = oWS.GetAuthors
dsRows = dotnetDS.item[1].firstChild.xml

* strip out references to XML namespaces that are
* no longer part of this XML document.
vfpDS = STRTRAN(STRTRAN(dsRows, "diffgr:", ""), "msdata:", "")

* Perform the conversion.
XMLTOCURSOR(vfpDS)

* See how it looks!
BROWSE

Not quite XSLT, but it got the job done quickly and easily!

For documentation on registering web services with Visual FoxPro and using IntelliSense to insert consumer code, see this MSDN article.



Figure 1. Browsing the a .NET data set.

My FoxPro skills are rusty, but this approach works for me. I’d be interested to hear how others have approached this issue. Did I make this more complicated than it needed to be?