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

Generate XML Using XSD 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I'm really confused about trying to use an XSD file to help create an XML file. Everything I have read says you can validate the XML against the XSD after the XML file is created to make sure it conforms, but is there some way of using the XSD to assist in properly creating the XML in the first place. There must be a way to to this without manually coding every field to export to XML. I apologize for this somewhat of a duplicate post that I had in the Vfp forum, but thought I might get an XML expert here.

Auguy
 
There are plenty of tools that can generate an empty xml from an xsd template.

Cheers,
Dian
 
Thanks, but I'm not sure that answers my basic question. I have no idea how to use the XSD provided by my client to help me in creating my XML file. Without reading/parsing the xsd file to find out the correct format, how do I know what text to write into the XML file. There must be a way to link my fields to the elements in the XSD to produce the proper XML text. If I can only use the XSD for validation, what good is the XSD to me? Do I have to manually go through the XSD and then write special code for every field that I want in the XML file? I must be missing something very basic here! OK..., here's what I would like to do.

1. Select data from my database.
2. Match the fields in my selected data to the elements in an existing XSD file.
3. Produce an XML file in the format specified by the XSD.

Auguy
 
You don't need to write special code for every field. Here is what you might consider instead.
[ul]
[li]Pull data from your database and create an XML document that is convenient for you.[/li]
[li]Use an XSLT to convert the document you create to the desired document.[/li]
[li]How do you build the XSLT? That is where you use the supplied XSD. A tool such as Stylus Studio can use an instance document (an example XML document such as you might create from your program) as a source, and an XSD as target, with its XSLT Mapper capability to produce an XSLT.[/li][/ul]

Tom Morrison
 
Thanks Tom,

That's what I was looking for. Just one more question. How exactly do I use the XSLT to convert the XML?

 
I am not at all familiar with Visual Foxpro, but it appears to have adopted a very "relational database" model for dealing with XML. This may not be the best thing for your application -- I just don't know.

A more brute force approach would be to create a valid XML document simply by writing a sequential file, in the form of:
Code:
<?xml [COLOR=red]...[/color]?>
<root>
<field1>[i]field1 value[/i]</field1>
<field2>[i]field2 value[/i]</field2>
<field3>[i]field3 value[/i]</field3>
[COLOR=red]...[/color]
<field[i]n[/i]>[i]field[/i]n[i] value[/i]</field[i]n[/i]>
</root>

Once you have this file, you could invoke MSXML as a command line process as documented here. MSXML will apply the XSL stylesheet and produce the transformed document.

There may be a direct way to use XSLT within VFP, but I was unable to find one in the fairly short amount of time I spent searching. Start your search on Microsoft's web site with the terms "foxpro" and "DOM". DOM is the acronym for Document Object Model which the object structure that is used by most programming languages to manipulate XML documents, including the application of XSLT.

Tom Morrison
 
Tom,

Thanks again for your detailed information, I really appreciate what you have posted here.

Auguy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top