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

XMLtoCURSOR 1

Status
Not open for further replies.

sebes

Programmer
Apr 5, 2011
45
RO
Trying co create a cursor from a memo field that contains a xml structure.
(The memo field is in fact on a remote view of a Access table).

I tryed to validate the contents with the free validator from and it gives no errors.

However, VFP gives "XML parse error".

Any advice is welcome.

Thanks.
 
One way would be to put the memo field contents into a memory variable (something like cXMLString) and then parse the string based on the XML Tags using the '<', '</', and '>' characters are identifiers.

Good Luck,
JRB-Bldr
 
Another option, once you have the XML data into a memory variable, would be to use the STRTOFILE() function to write that XML data into a text file and then process the file(s) as you would any other XML file.

Good Luck,
JRB-Bldr
 
VFP uses MSXML.XMLDocument to load and parse XML, it may be more accurate than the w3scools validator. Also w3scools is no authority on the subject, w3schools has nothing to do with the w3c consortium.

Bye, Olaf.
 
Also XMLTOCURSOR() is limited to XML representing tabular data only, it's not there to convert any XML to a cursor. The XMLAdapter class is more versatile to convert XML.

Bye, Olaf.
 
No idea how to use XML Adaptor . Anybody has a sample code ?

Thanks.
 
I got as far as loading my cXML but the last line gives an error message: Index or expression does not match an existing member of the collection.

LOCAL oXMLAdapter as XMLAdapter
oXMLAdapter = NEWOBJECT('XMLAdapter')
oXMLadapter.LoadXML(cXML)
oXMLAdapter.Tables.Item(1).ToCursor()

-gl
 
Sebes,

perhaps search here?

thread184-1517016
(in regard of the thread title: This also started as a question about xmltocursor which didn't work on that XML, too.)

Especially this part of the code, changed to use the remoteview.xmlfield as input:
Code:
lcXML = remoteview.xmlfield
loXMLAdapter = CreateObject("XMLAdapter")
loXMLAdapter.LoadXML(lcXML,.F.,.T.)
For Each loXMLTable in loXMLAdapter.Tables
   loXMLTable.ToCursor()
EndFor
Set

In case of Pete Schulte's XML it worked, XMLAdapter may also not detect a table in the XML you get from Access, then you need to take the xml string and parse it yourself.

Bye, Olaf.
 

Hmmmmmmm, this is encouraging because there are no error messages BUT there are no cursors created.

Could it be that the xml I supply doesn't "have" tables ? I mean whatever is there can not be turned into VFP tables ?

In that case I suppose that all I can do is to manipulate the xml manually and extract the data I need with various string functions...

-gl
 
Yes, that's what I said: "XMLAdapter may also not detect a table in the XML you get from Access, then you need to take the xml string and parse it yourself."

If loXMLAdapter.Tables.Count is 0, there is no tabular data detected in the xml.

You can use STREXTRACT() to extract portions of the XML, it's an ideal function to extract something between an opening and closing tag, eg STREXTRACT(cHTML,"<p>","</p>",1) does extract the first paragraph in some HTML text.

Bye, Olaf.
 


loXMLAdapter.Tables.Count is indeed ZERO...

Lots of learning today, no work done...

But I'm very happy with the response from this site.

Thanks all.
 
Sebes,

to add to the portfolio of possibilities

1. I already gave you STREXTRACT, in general XML is just a string you can decompose into it's data with string functions.

2. XMLAdapter, once loading the XML, has an object model representation of the xml. The Tables collection and Table.ToCursor() is not the end of the line. The IXMLDOMElement is simply an MSXML DOM Object (Msxml2.DOMDocument.4.0), which is documented in detail here, for example: and
You can use Nodes/Childnodes/Siblings to navigate the object tree of xml nodes the DOM Object contains and read out tagname and nodevalue, nodetypevalue etc., you can make use of IXMLDOMElement.selectnodes() to extract certain nodes and more.

3. MSXMLx.dll also offers more classes, eg SAXXMLReader.

Overal, XML is much to learn with a steep learning curve. This all has it's pros and cons. It's almost a science what you can do with MS or other vendors XML APIs and SDKs, but it all boils down to string manipulation anyway.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top