[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

XSD Advice

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
andyw27
Asked:
andyw27
1 Solution
 
Bob LearnedCommented:
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
 
drichardsCommented:
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
 
andyw27Author Commented:
Thanks that's great.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now