Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlAdapter and Schema

Status
Not open for further replies.

wbehning

Programmer
Nov 14, 2001
47
US
I am receiving an xml document from a HTTP request. This document contains no schema. So I used Visual Studio to create a schema file (customers.xsd) from this xml document. In VFP I then issue the following commands:


...

loXmlAd = CREATEOBJECT("xmladapter")
loXmlAd.XMLSchemaLocation = "..\customers.xsd"
loXmlAd.LoadXML(lcXml,.f.,.t.)

After this is run, loXmlAd.Tables.Count = 7, and I can issue the loXmlTables.ToCursor() command and it will create the tables according to the schema file. However, none of the cursors created contain any data from the XML document.

How do I get the data from the xmladapter into the schema cursors?
 


Have you considered using XMLTOCURSOR()? According to the help file:
Visual FoxPro interprets XML files with or without schema. If no schema is provided, Visual FoxPro makes two passes through the XML data. The structure is determined during the first pass; the conversion is performed during the second pass. Visual FoxPro uses either external or internal schema to determine the cursor or table structure before making a single pass through the XML data.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Yes, I see that in the help file as well. But it does not explain how to utilize an external schema. None of the arguments for XmlToCursor() reference an external schema.
 
I figured it out. I had to modify the HTTP response XML. Once I modified line #2, the table.tocursor() function created the cursor and populated them as well.

This is a snippet of the HTTP response, Note Line 2.

1 <?xml version="1.0" encoding="UTF-8"?>
2 <export_customers_response >
3 <authentication>
4 <revision>2.0</revision>
5 <reseller_shortcut>acme</reseller_shortcut>
6 <user_email>johnsmith@acme.net</user_email>
7 </authentication>
8 <customers>
9 <customer>
10 <customer_number>AC0127</customer_number>
.
.
.

I modify line 2 to read:
<export_customers_response xmlns="
1 <?xml version="1.0" encoding="UTF-8"?>
2 <export_customers_response xmlns="3 <authentication>
4 <revision>2.0</revision>
5 <reseller_shortcut>acme</reseller_shortcut>
6 <user_email>johnsmith@acme.net</user_email>
7 </authentication>
8 <customers>
9 <customer>
10 <customer_number>AC0127</customer_number>
.
.
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top