Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't convert this XML to cursor
Message
From
14/10/2005 20:16:26
 
 
To
14/10/2005 18:15:27
Mike Sue-Ping
Cambridge, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01059325
Message ID:
01059367
Views:
9
Mike,

>Thanks for the quick fix Borislav. ALthough it loads now, the resulting cursor looks strange with many blank rows. The web service said that the returned XML would be a "File" object. Does that make any sense to you? It looks to me like there should be several tables but XMLAdapter.LoadXML() does not get any XMLTables.

There is a way to get the data you want, using XPath features in VFP9 XMLAdapter. I've been doing demos of this type of problem in my XMLAdapter session today at SouthWest Fox, so I did a simple demo for you, using your XML pasted into a file called "testing.xml".

To make it work, I had to strip out the namespace info from the top-level tag and also add a pair of "root" tags around the top-level tag, since it represents a table and the XPath features must search for tables inside the first tag (now will be inside root tag).

Paste this code into a PRG and run it (after putting your XML into testing.xml). Note: I did not include all fields, but you can easily see how to finish the job. :-)
DO clearenv
LOCAL oxa AS xmladapter
oxa=CREATEOBJECT("xmladapter")

?
?
?
? "First, look at the original XML (in testing.xml)"

WAIT WINDOW "Press a key to view the XML"
CLEAR

* show the beginning XML file
MODIFY FILE testing.xml NOMODIFY

* tell XMLAdapter we don't have a schema
oxa.XMLSchemaLocation=""
* strip out namespace from first element
* and wrap everything after the XML tag inside
* a new Root element. This allows us to then use
* XPath to point to the tables and fields inside
* the <Root></Root> tags.
oxa.LoadXML( ;
  STRTRAN(STRTRAN(FILETOSTR("testing.xml"), ;
    [xmlns="http://www.Somesite.com/SomeWebService"],[]),;
    "?>", "?><Root>") + "</Root>" )

* now output the resulting XML structure to show
* what was loaded into the oxa.IXMLDOMElement.xml
?
?
?
? "Now output the resulting XML structure to show"
? "what was loaded into the oxa.IXMLDOMElement.xml"
TEXT
STRTOFILE(oxa.IXMLDOMElement.xml, "FromDOM.txt")
MODIFY FILE FromDOM.txt NOMODIFY
ENDTEXT
WAIT WINDOW "Press a key to show the resulting XML"

STRTOFILE(oxa.IXMLDOMElement.xml, "FromDOM.txt")
MODIFY FILE FromDOM.txt NOMODIFY
CLEAR
?
?
?
? "Ready to create the cursors"
? "Escape each Browse to create the next table"
?
? "NOTE: You will have to add more XMLField"
? "objects in the code to get all the fields"
WAIT WINDOW "Press a key to create the cursors"

* GetFileResult table
oTable = CREATEOBJECT("XMLTable")
oTable.XMLName = STRCONV("getFileResult",5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = "GetFileResult"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("dataError",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "dataerror"
oField.DataType = "L"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("errorString",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "errorString"
oField.DataType = "M"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("tblFilesID",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "tblFilesID"
oField.DataType = "I"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("openDate",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "opendate"
oField.DataType = "T"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("closeDate",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "closedate"
oField.DataType = "T"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("tblUsersID_Originator",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "tblUsersID_Originator"
oField.DataType = "I"
oTable.Fields.Add(oField, oField.XMLName)

*** You add more fields here for this table

oxa.Tables.Add(oTable, oTable.XMLName)

* escrowInfo table
oTable = CREATEOBJECT("XMLTable")
oTable.XMLName = STRCONV("getFileResult/escrowInfo",5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = "escrowinfo"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("dataError",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "dataerror"
oField.DataType = "L"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("errorString",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "errorString"
oField.DataType = "M"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("tblFilesID",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "tblFilesID"
oField.DataType = "I"
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("EscrowNumber",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "escrownumber"
oField.DataType = "C"
oField.MaxLength = 20
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("EstimatedCloseDate",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "estimatedclosedate"
oField.DataType = "T"
oTable.Fields.Add(oField, oField.XMLName)

*** You add more fields here

oxa.Tables.Add(oTable, oTable.XMLName)

* titleInfo table
oTable = CREATEOBJECT("XMLTable")
oTable.XMLName = STRCONV("getFileResult/titleInfo",5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = "titleinfo"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("dataError",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "dataerror"
oField.DataType = "L"
oTable.Fields.Add(oField, oField.XMLName)

*** You add the remaining fields here

oxa.Tables.Add(oTable, oTable.XMLName)

* addressInfo table
oTable = CREATEOBJECT("XMLTable")
oTable.XMLName = STRCONV("getFileResult/addressInfo",5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = "addressinfo"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("dataError",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "dataerror"
oField.DataType = "L"
oTable.Fields.Add(oField, oField.XMLName)

*** You add the remaining fields here

oxa.Tables.Add(oTable, oTable.XMLName)

* now output and browse the 4 cursors
oxa.tables(1).toCursor()
BROWSE
oxa.tables(2).toCursor()
BROWSE
oxa.tables(3).toCursor()
BROWSE
oxa.tables(4).toCursor()
BROWSE
CLEAR
>
>
>Mike
>
>
>>Mike,
>>I just copy and paste your XML text into a file. Made first line to begins from 0 (no spaces before >>
>>And
>>
>>XMLTOCURSOR("Test.XML","cTest",512) && 512 means the string you passed is file name
>>
>>
>>
>>>Hi,
>>>
>>>I'm trying to convert some XML into a VFP cursor(s). XMLAdapter's LoadXML fails with the following:
>>>
>>>
>>>XMLError: XML Parse Error: Invalid XML declaration.
>>>Line 1, Position 5   <?xml version="1.0" encoding="utf-8" ?>
>>>
>>>
>>>XMLTOCURSOR() also fails with a similar error. Any ideas what is wrong?
>>>
>>>
>>>
>>>  <?xml version="1.0" encoding="utf-8" ?>
>>>  <getFileResult xmlns="http://www.Somesite.com/SomeWebService">
>>>  <dataError>false</dataError>
>>>  <errorString />
>>>  <tblFilesID>749</tblFilesID>
>>>  <openDate>2005-10-13T12:18:23.6330000-07:00</openDate>
>>>  <closeDate>0001-01-01T00:00:00.0000000-08:00</closeDate>
>>>  <tblUsersID_Originator>23064</tblUsersID_Originator>
>>>  <tblTypesID_Status>69</tblTypesID_Status>
>>>  <tblTypesID_FileType>14</tblTypesID_FileType>
>>>  <salePrice>0</salePrice>
>>>  <lastAccessesDate>2005-10-14T09:59:23.9170000-07:00</lastAccessesDate>
>>>  <listingPrice>0</listingPrice>
>>>  <CancelDate>0001-01-01T00:00:00.0000000-08:00</CancelDate>
>>>  <ArchiveDate>0001-01-01T00:00:00.0000000-08:00</ArchiveDate>
>>>  <Terms>Some text goes here.</Terms>
>>>  <fileID_old>0</fileID_old>
>>>  <tblPrePaidPurchasesID>80</tblPrePaidPurchasesID>
>>>  <RegionType>163</RegionType>
>>>  <isTest>false</isTest>
>>>  <fileStatus>Open</fileStatus>
>>>  <fileType>Sale</fileType>
>>>  <fileOriginatorName>Somebody</fileOriginatorName>
>>>  <escrowInfo>
>>>  <dataError>false</dataError>
>>>  <errorString />
>>>  <tblFilesID>749</tblFilesID>
>>>  <EscrowNumber>ESC12345</EscrowNumber>
>>>  <EstimatedCloseDate>2005-11-12T00:00:00.0000000-08:00</EstimatedCloseDate>
>>>  <ContractAcceptanceDate>2005-10-13T00:00:00.0000000-07:00</ContractAcceptanceDate>
>>>  <EstimatedDaysUntilClose>30</EstimatedDaysUntilClose>
>>>  </escrowInfo>
>>>  <titleInfo>
>>>  <dataError>false</dataError>
>>>  <errorString />
>>>  <tblFilesID>749</tblFilesID>
>>>  </titleInfo>
>>>  <addressInfo>
>>>  <dataError>false</dataError>
>>>  <errorString />
>>>  <tblFilesID>749</tblFilesID>
>>>  <tblAddressesID>22631</tblAddressesID>
>>>  <streetNumber>450</streetNumber>
>>>  <streetDirection />
>>>  <streetName>Test</streetName>
>>>  <streetSuffix>St</streetSuffix>
>>>  <city>City</city>
>>>  <zip>92749</zip>
>>>  <tblTypesID_State>22</tblTypesID_State>
>>>  <unit>102</unit>
>>>  <county />
>>>  <addressLine1>777 Test St</addressLine1>
>>>  <cityStateZip>City, ST 11111</cityStateZip>
>>>  </addressInfo>
>>>  </getFileResult>
>>>
>>>
>>>
>>>Mike
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform