This high level method takes an XML file created with CursorToXML and converts it back into a cursor. The method can create a cursor automatically, or use an input file you pass in (via a passed open alias name). In order to create the file a DTD like the one exported by CursorToXML must be present in order to provide the Type, Size and Precision attributes required to create the cursor.
You can also generically import XML as long as the basic structure is followed:
<xdoc> <cursorname> <row> <data1/> <data2/> </row> </cursorname> </xdoc>
The names of the elements are not relevant, but the hierarchy of document - root, cursor, row, field - must be intact.
In order to create the table on the fly the data fields need to have name, type, size and precision attributes, which can be provided either via DTD or with each field. See the XML document format below for an example.
Also check out the low level functions: BuildCursorFromXML() which uses the field attributes to create the cursor and ParseXMLToCursor() which retrieves the XML into the actual cursor/table. If the table already exists ParseXMLToCursor can import the data generically as long as the relative structure of
Importing exports from SQL Server and VFP's CursorToXML native function
wwXML can import data from SQL Server and VFP 7's CursorToXML XML formats, but it requires that the table structures preexist. In other words, wwXML can import but not use the schemas by these services (which differ significantly and are in constant flux). The following code demonstrates how to import a cursor in this fashion:
USE tt_cust CURSORTOXML("tt_cust","lcXML",1,48,0,"") USE oXML = CREATEOBJECT("wwXML") USE d:\temp\test.DBF EXCLUSIVE * or (better perf) SELECT * FROM TT_CUST WHERE .F. READWRITE INTO CURSOR TEST oXML.XMLToCursor(lcXML,"Test",1) BROWSE
Character - name of ALIAS or Empty on failure.
XML as a string value or an MSXML DOM Object.
Optional - output alias. This is the name of the cursor that will be created by this routine. NOTE: if this ALIAS() is already open records are appended to it. If no alias is provided a DTD is required in the XML input as generated by CursorToXML.
- Default value:* __wwXML
NOTE: If you don't pass an existing cursor in the lcAlias parameter the data must include a Schema/ DTD created by CursorToXML! XMLToCursor can only create a new cursor if the Schema/DTD is present. To export your data with a Schema/DTD use the nCreateDataStructure flag before exporting.
Performance will be best when importing with a Schema/DTD, or when importing into READWRITE CURSOR which performs two times faster than an EXCLUSIVE used FoxPro table. If you provide a table make sure it's used EXCLUSIVE which will be more than twice as fast as a non-exclusive table.
You can use the WWXML_USE_VFP_XMLTOCURSOR flag to determine whether this method uses VFP's XMLTOCURSOR() function. Requires VFP 7.0 SP1 to work! This will improve performance making import about two to three times faster on typical imports.
oXML = CREATEOBJECT("wwXML") *** Grab converted cursor with schema *** REQUIRES A SCHEMA or DTD!!! lcXML = FileToStr("tt_cust.xml") *** Create a cursor named TCustomers from XML input string oXML.XMLToCursor(lcXML,"TCustomers") SELE TCustomers BROWSE <<hr>> *** Alternately Use the IE DOM object to load the XML *** REQUIRED SCHEMA OR DTD!!! loIEDOM = CREATEOBJECT("MSXML2.DOMDocument") loIEDOM.LoadXML( lcXML ) ... manipulate the XML here *** Pass the DOM as input instead oXML.XMLToCursor(loIEDOM,"TCustomers") SELE TCustomers BROWSE <<hr>> *** Use an existing cursor as the structure *** NO SCHEMA OR DTD required USE TT_CUST COPY STRUC TO TEMP USE && Close explicitly USE TEMP *** Now load oXML.XMLToCursor(lcXML,"Temp")
See also:Class wwXML (High Level Methods)
Comment or report problem with topic