Relationships: modeling relational data in XML, part 3

The next approach uses named complex types and then generates the element structures from them. In this example, the types are typically declared together at the beginning of the document and then referenced later on. Our example formulated this way looks like this:


<xsd:schema

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


     <xsd:complexType name="customerElement">


     <xsd:sequence>


     <xsd:element name="Invoice" type="invoiceElement"

    maxOccurs="unbounded" />


     </xsd:sequence>


     </xsd:complexType>


     <xsd:complexType name="invoiceElement">


     <xsd:sequence>


     <xsd:element name="LineItem" maxOccurs="unbounded"

    />


     </xsd:sequence>


     </xsd:complexType>


     <xsd:element name="Customer" type="customerElement"

    />


    </xsd:schema>

In this model, each element is declared separately. However, the model of the element content (the complexType) is declared independently of the element name (the element declaration itself). This can lead to some headaches if elements with matching names have different content models. The third approach resolves this by using global element declarations, referenced using the ref attribute on the actual element declarations:


<xsd:schema

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


     <xsd:element name="Customer">:


     <xsd:complexType>:


     <xsd:sequence>:


     <xsd:element ref="Invoice" maxOccurs="unbounded"

    />:


     </xsd:sequence>:


     </xsd:complexType>:


     </xsd:element>:


     <xsd:element name="Invoice">:


     <xsd:complexType>:


     <xsd:sequence>:


     <xsd:element ref="LineItem" maxOccurs="unbounded"

    />:


     </xsd:sequence>:


     </xsd:complexType>:


     </xsd:element>:


     <xsd:element name="LineItem" />:


    </xsd:schema>:

Subscribers who liked this article also read:
Security considerations for mobile hardware
by Alan Zeichick, principal analyst, Camden Associates. Intel Corp. ...
Multithreaded technology and multi-core processors
by Craig Szydlowski, Infrastructure Processor Division, Intel Corp. ...

If you're interested in this topic, these articles may be helpful:

Data points: modeling relational data in XML, part 2
by Kevin Williams, founder and CEO, Blue Oxide Technologies. Intel Cor...
Final Cut Pro XML Interchange Format
Apple Inc. The Final Cut Pro XML Interchange Format provides extens...
XML Web services: the long-term security risks
by Andrew Yang, senior director of project management, Westbridge Tech...
Oracle Database 10g XML & SQL, Chapter 7: Putting It All Together with XML Pipeline, JSPs, and XSQL
by Mark Scardina, Ben Chang, and Jinyu Wang. McGraw-Hill Osborne Med...
Scaling XML parsing on Intel architecture
By Andy Longshaw, Content Master Ltd. Intel Corp. XML provides many b...

Related Jobs:

Microsoft Developer - Senior Consultant #1376 - MN - Richfield - Sogeti USA LLC
Microsoft Developer - Senior Consultant Req. ID: 1376 # Positions:...
Senior Web Applications Engineer #8476E6367126C442 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Web Developer/Front End #RX1000022062 - CA - Sunnyvale - Yahoo! Inc.
Web Developer/Front End, Structured Web Search Job No. RX10000...
Engineering Manager / Chief Architect #0D2000E1CDEE90F2 - CA - West Hollywood - Ask Jeeves,Inc.
Title Engineering Manager / Chief Architect City West Hollywood St...
Software Developer #BK-DEV - PA - Philadelphia - SunGard
Reference No.: BK-DEV Opening Date: July 17, 2007 Job Title: Softw...
Freelance Presentation Layer Architect #1977 - NY - New York - aQuantive, Inc.
Freelance Presentation Layer Architect Job ID: 1977 Business Unit:...
Data Migration Specialist #TEC00001143 - PA - Horsham - The Thomson Corporation
Data Migration Specialist – TEC00001143 Job Description ...
Technical Yahoo #RX1000023474 - CA - Sunnyvale - Yahoo! Inc.
Technical Yahoo Job No. RX1000023474 Location US - Sunnyvale ...
Senior Research Engineer #F2FDC48FE3C2DAE3 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Research Engineer City Oakland State CA Zip Code 94...
Senior Web Applications Engineer #C8469CF29B4A750B - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...