How to Import an XSD File

If most of the schema information you need is already contained within another XSD file, there is no reason to duplicate all that information into another file. Doing so is a recipe for disaster because by spreading XSD Schema information out across multiple files, you are only creating a nightmare situation should your XSD Schema ever need to be altered. Instead, you should use the "xsd:import" and "xsi:schemaLocation" tags in your XSD documents to import XSD files into another other XSD documents that require the same information. This ensures that when the time comes to update one of your documents, the changes will propagate out to any other documents automatically.

Instructions

    • 1

      Open your new XSD file in a text editor. For the tutorial, the following very simple XSD document will be used:

      <?xml version="1.0"?>

      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

      <xsd:element name="person">

      <xsd:complexType>

      <xsd:sequence>

      <xsd:element name="name" type="xsd:string"/>

      <xsd:element name="phone" type="xsd:string"/>

      <xsd:element name="address" type="xsd:string"/>

      </xsd:sequence>

      </xsd:complexType>

      </xsd:element>

      </xsd:schema>

      As you can see this XSD defines the structure of a database of persons, each with their own name, phone number and address. However, some of the details of the implementation are less than desirable: surely there is a better data definition out there for names, addresses, and phone numbers than the simple string. Ideally, our XSD document should be able to spot obviously invalid "phone numbers" like "12" or, even worse, something completely nonsensical like "I don't feel like giving you my phone number."

    • 2

      Add the following line to your XSD file, just below the "xsd:schema" line:

      <xsd:import namespace="kevinwalkersNS" schemaLocation="phoneNumber.xsd"/>

      <xsd:import namespace="kevinwalkersNS" schemaLocation="address.xsd"/>

      <xsd:import namespace="kevinwalkersNS" schemaLocation="englishNames.xsd"/>

      Now, you have imported three XSD files: one that defines a "phoneNumber" data type, another for an "address" data type, and a third for an "englishNames" data type. Each of them is in a name space named "kevinwalkersNS," and this prevents conflicts with other documents that may have similar variable names within them.

    • 3

      Edit the variable types of your elements that use the XSD documents you imported to use the schema contained within. In this case, the "xsd:string" should be replaced like so:

      <xsd:element name="name" type="kevinwalkersNS:englishNames"/>

      <xsd:element name="phone" type="kevinwalkersNS:phoneNumber"/>

      <xsd:element name="address" type="kevinwalkersNS:address"/>

Related Searches:

References

Comments

You May Also Like

  • How to Import XSD Into WSDL

    Web service description language (WSDL) is a model and format for describing web services using XML. A consumer can locate a service...

  • Example of the XSD File

    The file extension .xml is a text file that is commonly seen within XML schema. These files allow programmers and Web developers...

  • How to Use XSD in WSDL

    XSD and WSDL are XML schemas used to share functions with other programs. The schemas provide developers with an XML layout for...

  • How to Work With XSD Files

    XSD files are developer files that define "what elements and attributes may appear in an XML document," according to the website FileInfo.com,...

  • How to Open XSD Files

    An XSD (XML Schema Definition) file shows the relationship between the different elements in an XML (Extensive Markup Language) file. XML files...

  • How to Import Data from Another Database Into Access 2003

    When trying to import data from another database, a copy of the data that you import is created in the destination database,...

  • A Tutorial on XSD Files

    You create an XML Schema Document (XSD) any time you want to enforce a valid schema within your XML documents. The purpose...

  • How to Create Database Tables From XML and XSD Schemas

    The Filemaker Pro application is a database development tool that allows you to store multiple tables of data within a single file....

  • How to Create XSD VB

    There are two paths you can take to create XSD files from Visual Basic. If you have an existing XML document and...

  • How to Generate an XSD File

    An XSD file is an Extensible Markup Language or XML schema that is used to define various elements and attributes of an...

  • How to View XSD

    .XSD files are most commonly used by a program called XML Schema. They define the characteristics of an XML document and what...

  • How to Understand XSD

    An XSD is an XML Schema Definition, a set of rules describing the structure of XML markup. XSDs are used to define...

  • How to Validate an XSD File

    XML Schema Documents (XSD) are designed to provide a source that validators can use to validate XML databases for valid structure and...

  • How to View Xsd Files

    Many different file types can be found on an operating system, some created by Windows itself, and others created by applications that...

Related Ads

Featured