When Should XSD Files Be Used? When Should XSD Files Be Used? xml xml

When Should XSD Files Be Used?


Your talk of "class files" and "class structure" suggests you are thinking of your data structure as being primarily defined by programming language data structures - that is, you are taking a programming-centric view rather than a data-centric view. That's rather missing the point of XML, which starts from the viewpoint that if applications (especially applications that are independently developed) are to exchange data effectively, then the design of the data needs to be independent of the design of the applications. This "design of the data" is often expressed in a schema (either an XSD schema, or some other kind), and it represents a contract between the communicating applications (just as RFC822 defines the data that an email application must handle). By validating data against the schema, applications can be sure that what they are being sent is conformant with the agreed specification.


XSD allows you to define schema objects. There are many tools out there that take xsd as input and generate classes for those objects. Many of these tools also generate Marshalling/Unmarshalling - (converting objects to xml and vice versa) code as well in addition to just the plain value object classes. There are many applications that need to convert in-memory object instances to xml representation and reverse and without an xsd and a suitable tool you would need to write the conversion code for each object by hand which can be error prone and/or may be very expensive depending on number of classes in your domain. The xml representatation of an object may not be valid as well if coming from an external source, having an xsd can validate these and let you unmarshal them to object instances.

For further info, see

Castor/Xml Beans etc for java

XSD.exe tool for Microsoft Tech.


Copying from W3Schools:

"

The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.

An XML Schema:

- defines elements that can appear in a document- defines attributes that can appear in a document- defines which elements are child elements- defines the order of child elements- defines the number of child elements- defines whether an element is empty or can include text- defines data types for elements and attributes- defines default and fixed values for elements and attributes

"

In practice it defines the XML that is valid for a given purpose - fro example a system developer can use it to define what consitutes a valid XML file to entry to their system.