Search code examples
xmlcursorfoxpro

XMLAdapter Class in Visual FoxPro 9


I’m using Visual FoxPro 9 on Vista in the administrator account. I’m trying to execute the following program:

cFile = "c:\XMLAdapter\CustomerXML.xml"
adapter = CREATEOBJECT("XMLAdapter")
adapter.LoadXML(cFile,.T.)
adapter.Tables(1).ToCursor()

I’ve copied this program verbatim (except for changing the path of the XML file) from an article in Code Magazine ( Converting XML to VFP Cursors Using the XMLAdapter ). When I execute it, I get the following error: Index or expression does not match an existing member of the collection. It is crashing on the last line of the program.

In the same article, there is also this program:

cFile = "c:\XMLAdapter\EmployeeXML.xml"
OPEN DATABASE (_samples+"\northwind\northwind")
SELECT employeeid, lastname ;
FROM Employees;
INTO CURSOR curEmployees
adapter = CREATEOBJECT("XMLAdapter")
adapter.AddTableSchema("curEmployees")
adapter.ToXML(cFile,,.T.) 

This works perfectly.

I’d really appreciate it, if anyone could help me understand why the first program is crashing?

Thanks


Solution

  • The XMLAdapter class is fussy about the types of XML it will accept. I can't see a link to an actual file that represents c:\XMLAdapter\CustomerXML.xml in the article, is there one I haven't seen or is this just used for demonstration purposes? If there isn't one, I expect you created your own valid XML file: analyzing the file produced by your second code example should be enough to create something acceptable to the XMLAdapter.

    If you want documentation and examples of the XMLAdapter, the top links on a Google books search will help