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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLTOCURSOR - VFP7 Code

Status
Not open for further replies.

bobmpalmer

Programmer
Aug 19, 2003
161
GB
I am trying to provide a data transfer routine using VFP to XML and am perplexed as to why if I execute the functions fron cursor to var and reverse all works fine but if I try to do the same to a file it fails with an error - XML parse error invalid at top level of the document Line 1 position 1

this works:-
CursorToXML("csrExport2","resinames",1,8)
USE
XMLTOCURSOR(resinames,"csrExport2")
this doesn't
CursorToXML("csrExport2","resinames.xml",3,512,0,"")
USE
XMLTOCursor("resinames.xml","csrExport2")

I have checked the msxml3 and msxml4 dlls and upgraded their versions from MSDN any help please?




Bob Palmer
The most common solution is H2O!
 
I'm a bit confused. Is it CURSORTOXML that doesn't work, or XMLTOCURSOR?

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Appologies
CURSORTOXML works fine in both methods and in the second (failing) method produces what seems to me a perfectly valid XML file but XMLTOCURSOR won't re load it just comes back with the indicated error

Bob Palmer
The most common solution is H2O!
 
Craig don't know if it helps but this is the XML file created by method 2

<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?>
- <VFPData>
<row category="Behaviour" />
<row category="Care Notes" />
<row category="Chiropody" />
<row category="Doctor's Notes" />
<row category="Dressings" />
<row category="Hairdressing" />
<row category="Medication" />
<row category="Nurse notes" />
<row category="Physical Disabilitie" />
<row category="Physiotherapy" />
<row category="Religious Needs" />
<row category="Special Care" />
<row category="Speech Therapy" />
<row category="Waterlow Assessment" />
<row category="bathing" />
</VFPData>

Bob Palmer
The most common solution is H2O!
 
Thanks guys, I've solved the problem thanks. It appears that you need to specify the nFlag value 512 for the parser to identify the file as valid e.g.
XMLTOCursor("resinames.xml","csrExport2",512)!!!

Bob Palmer
The most common solution is H2O!
 
The XMLtoCursor() function is somewhat limited and does not work as expected with every XML structure. Or I should say, as I expected. In one case I was being sent only the 2 levels of data shown in blue here. In order for this function to work, I had to add a wrapper shown in purple.
Code:
[COLOR=purple]<MainInfo>[/color]
 [COLOR=blue] <Group1>
    <Item1>10</Item1>
    <Item2>20</Item2>
    <Item3>30</Item3>
  </Group1>[/color]
[COLOR=purple]</MainInfo>[/color]
A second problem I encountered with XMLtoCursor() was that if there was data in multiple levels or groups, then the cursor would then be created with multiple records. Once the XML data was parsed from a different level or group, then the data in the cursor henceforth was placed on the next record, and so on. Opening and browsing the cursor looked like the data was taking stairsteps downward. So I had to continually test which record the data was on as I was picking up the data.

One neat trick I learned was to create the destination cursor first with the fields you needed, that way only the elements needed would be picked up and also they'd be in a field with data type and size you expect.
Code:
CREATE CURSOR curTemp (CustomerName C(40), CurrentBalance N(12,2))
xmlCnt = XMLTOCURSOR(StringXML,"curTemp",8192)
* 8192 places incoming XML into open table/cursor
SELECT "curX"
So XMLtoCursor is generally only suitable for simple XML. A better solution was to use the XmlAdapter object. Here is a simple example:
Code:
PRIVATE oXml, iXml
oXml = CREATEOBJECT("XmlAdapter")
oXml.loadXml(IncomingXML)
iXml = oXml.IXMLDOMElement
IF oXml.isLoaded
   cDate = VAL(iXml.getElementsByTagName("EventDate").item(0).text)
   cInfo = VAL(iXml.getElementsByTagName("EventDetail").item(0).text)
ENDIF
RELEASE oXml, iXml
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top