0

What is the suggested approach to a following problem, which seems to be quite common to me.

We need to generate the xml document for which we have a schema, xsd file. Our application generates the data that is to be put into the document. What kind of xsl file should be used for that? I believe there must be snippets that would be common for all such tasks, because the xsd format is constant.

For example I imagine xsd is first preprocessed to generate a data template. Then the application may use this data template to generate real data. Finally there is main processing which produces the output file. And the main processing xsl stylesheet could also be auto-generated from xsd. Of course after all the auto-processing, manual tuning of the stylesheets is done.

I see such specific common tasks:

  • Treatment of minOccurs=0 elements. They would be generated only if the data contains given element.
  • Default values if no data is given, but the element is obligatory.
  • Controlling alternative elements with a parameter or data node.
Jarekczek
  • 7,456
  • 3
  • 46
  • 66

2 Answers2

0

In general there are an infinite number of documents that conform to any given xml schema. There are tools that generate "typical" instances, but their output will never be predictable. There are also tools that, given a source and target schema, guide you to define a transformation from one to the other (the best known is probably from Altova). Again, this will only work in simple/special cases. But it may be just what you are looking for.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • For completeness, could you (or anyone) provide the name of the product, since Altova released dozens of them. – Jarekczek Nov 03 '12 at 17:16
  • I think they've gone through several renamings/repackagings since I last looked, but you could start here: http://www.altova.com/solutions/xml-mapping-tools.html – Michael Kay Nov 04 '12 at 09:50
0

Jarekczek, even though your idea seems quite general, maybe it is still stated in too narrow way? How about removing the words "xsl stylesheets to" from your question? Isn't it better to use the language X in which your application is written without struggling with xslt processors?

Others have already asked for that, these question seems to cover the topic for specific languages:

I'm still investigating the subject. If the questions are tagged properly, then searching for [xsd] [code-generation] should be a good starting point.

Note also that what you're trying to achieve may be call xsd-based marshalling, being a part of XML data binding (wiki).

Community
  • 1
  • 1
Jarekczek
  • 7,456
  • 3
  • 46
  • 66
  • The language X, in which my application is written, is a custom proprietary language. There are no tools generating code for it. So I need either a customizable code generator or an xslt solution. The language gives me access to COM and thus MSXML. – Jarekczek Nov 04 '12 at 14:05