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

Thank you for the sample. I'm going to try to request an XML schema as Sergey pointed out. If I cannot obtain one, I guess your method is going to have to do.

Mike


>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
Previous
Reply
Map
View

Click here to load this message in the networking platform