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

Ho to write XML starting from XML schema

Status
Not open for further replies.

lclock

Programmer
Jan 24, 2009
15
IT
Hi, for the first time i have to deal with XML in my VFP program.
I have to send some information to a government agency via XML file.
The agency provide a XML schema file (i've attached it , available for two weeks only).
I was able to load the schema with xmladapter obj but .. then
what i've to do to put my data into and then generate my xml file to send ?
Thank you !
 
Thank's stfaprc, i've already read that article and i found it useful, but it doesn't solve my problem or better i'm not able to well understand.
In the article there's an example of schema use, but it uses schema and also xml with data and so at the end it gots some cursor.
In my case i havent the data file but i have to generate it.
So my doubt is : should i read the schema, understand the structure and then use addtableschema? and how can i deal with datatypes? Or should i use the MSXML objects and work with appendChild and so on?
Thank's
 
Let me quote ome of one important line of that article:

XMLAdapter class can also create an XML document representing the contained tables and fields that have been populated.

So XMLAdapter is not a one way ticket. Besides LoadXML() And ToCursor() there is also AddTableSchema() and ToXML().

The articel also shows with a simple example of a single cursor.

And yes, although you already have your schema, AddTableSchema is needed, at least it's the easiest way to attach a cursor containing data that you want to be part of the xml to generate.

But still you'd need to know what cursors you need and what their structure should be. To determine that, the easiest thing would be to have some sample XML data and first go the route of reading in that XML to vfp cursors, and then go the inverse route. The XML schema still comes in handy to validate the initial XML input and your output data would also be validated against the allowed values for example.

You can determine the structures you need from the xsd, but it includes much overhead information not only about the data types but also allowed value ranges. There is no easy XSDToCursorStructure() command unfortunaltely. That's what the article does not show at least.

If you do o=createobject("xmladapter") and o.xmlschemalocation = getfile("xsd") and locate your xsd file, unfortunately the XmlAdapter does not create the xmltables and xmlfields you'd need to know the database structure in the xmladapters tables collection and each tables item fields collection. It results in o.Tables.Count being 0.

So with a little XMLsample you'd have better luck. Then you could LoadXML, would ideally have a tables collection and with each table could do a ToCursor(), then you'd have the vfp cursor/table structures. And then you could go the reverse way, as already said by AddTableSchema() for each single cursor and then would finally call ToXML after all needed cursors are added.

And the quintessence regarding th xsd: On both the way from xml to vfp cursors and from vfpcursors to xml it's used to validate either the xml or the vfpcursors and their data. But it's not taken to create some CREATE TABLE/CURSOR sql or the tables/cursors themselves. This is beyond the xmladatper class. Perhaps you're lucky with West Winds wwXML class, that has a CreateCursorFromSchema() function, although in this case it would be more than one cursor.



If it won't work for that task, it may help you anyway.

Bye, Olaf.
 
Thank you Olaf,
your post is very clear and it confirms my suspect!
Unfortunatly i've only got the schema with no data, and the schema is also complex.
I will look at the west-wind object.
If i solve my problem with some interesting solutions i will post it.
Bye lclock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top