Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
XML Schema Infoset Model, Part 2
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
6. Elements and attributes
  


Exercise 6: Create a global attribute group, global attribute, local attribute, and attribute reference page 5 of 6


Using the XML Schema Infoset Model APIs and adding on to the schema created in Exercise 5: Create a global, local, and element reference, create the following schema document:


<?xml version="1.0"?>
<schema
  targetNamespace="http://www.eclipse.org/xsd/examples/po"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:po="http://www.eclipse.org/xsd/examples/po">
 
  <simpleType name="USState">
    <restriction base="string">
      <enumeration value="AK"/>
      <enumeration value="AL"/>
      <enumeration value="AR"/>
    </restriction>
  </simpleType>
   
  <simpleType>
    <list itemType="po:USState"/>
  </simpleType>
   
  <complexType name="PurchaseOrderType">
    <sequence>
      <element minOccurs="0" name="state" type="po:USState"/>
      <element ref="po:notes"/>
    </sequence>
    <attribute name="color" type="string"/>
    <attribute ref="po:lang"/>
    <attributeGroup ref="po:shapeAttributes"/>
  </complexType>
   
  <element name="notes" type="string"/>
   
  <attributeGroup name="shapeAttributes">
    <attribute name="size" type="string" use="optional"/>
    <attribute name="length" type="int"/>
  </attributeGroup>
   
  <attribute name="lang" type="string"/>
   
</schema>
                                

Hint: You will need to create an org.eclipse.xsd.XSDAttributeUse for the local attribute and attribute reference.

New constructs created in this exercise:

  • <attributeGroup> - Global attribute group with name="shapeAttributes"
  • <attributeGroup> - Attribute group reference with ref="po:shapeAttributes"
  • <attribute> - Local attribute with name="size", type="string" and use="required"
  • <attribute> - Local attribute with name="length", type="int" and use="optional"
  • <attribute> - Local attribute with name="color", type="string"
  • <attribute> - Global attribute with name="lang", type="string"
  • <attribute> - Attribute reference with ref="po:lang"
Solution: Exercise 6 solution


Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact