Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML Object to Cursor?
Message
General information
Forum:
Visual FoxPro
Category:
Web Services
Miscellaneous
Thread ID:
00787537
Message ID:
00787610
Views:
23
Michael
Assuming you have an XML file or string, here is a way to traverse it manually. This example will save it to a cursor with field names similar to the xml nods.
loXML = CREATEOBJECT( "MSXML2.DOMDocument.3.0" )
loXML.loadXML( SomeXMLString ) && or loXML.Load ( SomeXMLFile )
loRoot = loXML.documentElement
IF ISNULL( loRoot )
   RETURN 'Invalid XML file'
ENDIF
CREATE CURSOR mycursor ( somefield1 C(10), somefield2 C(8), xmlnode3 C(4) )
append blank
*** field 1
loElement= loRoot.selectSingleNode( "SomeField1" ) && careful, case sensitive
IF ISNULL( loElement )
   COMRETURNERROR( 'YourWebServiceClass', 'SomeField1 node not found' )
ELSE
   IF EMPTY( loElement.Text )
      COMRETURNERROR( 'YourWebServiceClass', 'The field is empty...' )
   else
      replace mycursor.somefield1 with loElement.Text
   endif
ENDIF
*** field 2
loElement= loRoot.selectSingleNode( "SomeField2" )
IF ISNULL( loElement )
   COMRETURNERROR( 'YourWebServiceClass', 'SomeField2 node not found' )
ELSE
   IF EMPTY( loElement.Text )
      COMRETURNERROR( 'YourWebServiceClass', 'The field is empty...' )
   else
      replace mycursor.somefield2 with allt(loElement.Text)
   endif
ENDIF
*** field 3 - this one is under a branch named SomeBranch
loElement= loRoot.selectSingleNode( "SomeBranch/XmlNode3" )
IF ISNULL( loElement )
   COMRETURNERROR( 'YourWebServiceClass', 'node not found' )
ELSE
   IF EMPTY( loElement.Text )
      COMRETURNERROR( 'YourWebServiceClass', 'The field is empty...' )
   else
      replace mycursor.xmlnode3 with loElement.Text
   endif
ENDIF
Also, if you have many records in one xml file or string, you can traverse them with SelectNodes instead of SelectSingleNode. Drop me a line if you need an example of this one.

HTH
Jaime

>I'm calling a web service from VFP8, and I am getting back an object which seems to be a container for a series of objects which all together define an XML document.
>
>I saw a message with an example of traversing the object (for the google web service) but I'm a bit new at this and in my environment it's tough to get the right node properties and property names (I'm not directly connected to the web service)
>
>Is there a technique or class that will help me get the nested object data into a cursor?
>
>If I have to do this manually, where can I find a good reference?
>
>TIA
>
>Michael Hogan
>Ideate, LLC
Why do programs stop working correctly as soon as you leave the Fox?
Previous
Reply
Map
View

Click here to load this message in the networking platform