Solved

XSD Advice

Posted on 2013-10-24
3
188 Views
Last Modified: 2013-11-07
Hi,

I’m after some advice regarding XSDs.  I have created a class that extracts data from a database and exports it to an XML document.
I have now been asked to produce a XSD.  I noticed that in visual studio 2010 there is an option to open a XML and automatically generate a XSD document.  Is this advisable?

I suppose if that method is used I should make sure that all elements are populated with the correct data?

Any advice appreciated?
0
Comment
Question by:andyw27
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39599238
Have you tried to use that option to generate an XSD, so that you can see what the output is.  You should be able to use an XSD to validate any XML to see if it meets the schema requirements.
0
 
LVL 19

Accepted Solution

by:
drichards earned 500 total points
ID: 39602237
The auto-generated XSD is a good starting point, but if your XML is more flexible than your sample XML then you will need to fix it up as it will not be fully correct.

For example, you need to check min/maxOccurs on elements, check  attribute types, create enumerations for values that are enumerations, create substitution groups or derived types if necessary, etc.  The generated schema will match the XML used to produce it but if your input XML did not represent all possible options then the schema will be deficient.

Examples of the type of things that are missed:
1. Optional elements or attributes that were not in the XML used to produce the schema
2. More complex productions like sequence of choice will not be correctly inferred
3. An attribute value that is supposed to be string may come out as a numeric type if only digits are present.

You get the idea.  The generated schema is still a good place to start in most cases, though, and if your XML is really simple the generated XSD may be entirely adequate.
0
 

Author Comment

by:andyw27
ID: 39629932
Thanks that's great.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question