blob: 61279a3dc4c7f85f29fe2e7e3ad18a297a2173e9 [file] [log] [blame]
<html>
<!-- This panel generated from the developerWorks XML tag set for tutorials, Version 3.0.2. (C) Copyright 2000, 2002 IBM Corporation. All rights reserved. -->
<head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Pulling it all together</title></head><body vlink="663366" alink="330000" text="000000" bgcolor="ffffff"><script language="javascript">
<!--
var emailAbstract="This tutorial gives you the building blocks you need to set up and work with the XML Schema Infoset Model. It shows how to create all of the different constructs within the XML Schema Infoset model. This tutorial is the second of a two-part series.";
var justTitle="XML Schema Infoset Model, Part 2";
var tutorialPrereqs="http://www.ibm.com/developerworks/edu/os-dw-os-schema2-i.html";
var menu1blurb="Before you start";
var menu2blurb="Overview of XML Schema documents";
var menu3blurb="Simple types";
var menu4blurb="Complex types";
var menu5blurb="Content models";
var menu6blurb="Elements and attributes";
var menu7blurb="Pulling it all together";
var menu8blurb="You try it!";
var menu9blurb="Summary and resources";
var browser = "x";
if (navigator.userAgent.indexOf("Mozilla/4") != -1) browser = "N3";
else if (navigator.userAgent.indexOf("Mozilla/3") != -1) browser = "N3";
else browser = "x";
if (browser=="N3")
{
var menu1over=new Image(108,68);
var menu1out=new Image(108,68);
var menu2over=new Image(108,68);
var menu2out=new Image(108,68);
var menu3over=new Image(108,68);
var menu3out=new Image(108,68);
var menu4over=new Image(108,68);
var menu4out=new Image(108,68);
var menu5over=new Image(108,68);
var menu5out=new Image(108,68);
var menu6over=new Image(108,68);
var menu6out=new Image(108,68);
var menu7over=new Image(108,68);
var menu7out=new Image(108,68);
var menu8over=new Image(108,68);
var menu8out=new Image(108,68);
var menu9over=new Image(108,68);
var menu9out=new Image(108,68);
var topmainover=new Image(77,15);
var topmainout=new Image(77,15);
var bottommainover=new Image(77,15);
var bottommainout=new Image(77,15);
var topsectionover=new Image(98,15);
var topsectionout=new Image(98,15);
var bottomsectionover=new Image(98,15);
var bottomsectionout=new Image(98,15);
var topfeedbackover=new Image(80,15);
var topfeedbackout=new Image(80,15);
var bottomfeedbackover=new Image(80,15);
var bottomfeedbackout=new Image(80,15);
var toppreviousover=new Image(77,15);
var toppreviousout=new Image(77,15);
var bottompreviousover=new Image(77,15);
var bottompreviousout=new Image(77,15);
var topnextover=new Image(60,15);
var topnextout=new Image(60,15);
var bottomnextover=new Image(60,15);
var bottomnextout=new Image(60,15);
var topnextsectionover=new Image(108,15);
var topnextsectionout=new Image(108,15);
var bottomnextsectionover=new Image(108,15);
var bottomnextsectionout=new Image(108,15);
menu1over.src="imagemaster/himenu1.jpg";
menu1out.src="imagemaster/menu1.jpg";
menu2over.src="imagemaster/himenu2.jpg";
menu2out.src="imagemaster/menu2.jpg";
menu3over.src="imagemaster/himenu3.jpg";
menu3out.src="imagemaster/menu3.jpg";
menu4over.src="imagemaster/himenu4.jpg";
menu4out.src="imagemaster/menu4.jpg";
menu5over.src="imagemaster/himenu5.jpg";
menu5out.src="imagemaster/menu5.jpg";
menu6over.src="imagemaster/himenu6.jpg";
menu6out.src="imagemaster/menu6.jpg";
menu7over.src="imagemaster/himenu7.jpg";
menu7out.src="imagemaster/menu7.jpg";
menu8over.src="imagemaster/himenu8.jpg";
menu8out.src="imagemaster/menu8.jpg";
menu9over.src="imagemaster/himenu9.jpg";
menu9out.src="imagemaster/menu9.jpg";
var mainblurb="Main menu";
var sectionblurb="Section menu";
var feedbackblurb="Give feedback on this tutorial";
var previousblurb="Go to previous panel";
var nextblurb="Go to next panel";
var nextsectionblurb="Go to next section";
topmainover.src="../default/i/h-main.gif";
topmainout.src="../default/i/main.gif";
bottommainover.src="../default/i/h-main.gif";
bottommainout.src="../default/i/main.gif";
topsectionover.src="../default/i/h-section.gif";
topsectionout.src="../default/i/section.gif";
bottomsectionover.src="../default/i/h-section.gif";
bottomsectionout.src="../default/i/section.gif";
topfeedbackover.src="../default/i/h-feedback.gif";
topfeedbackout.src="../default/i/feedback.gif";
bottomfeedbackover.src="../default/i/h-feedback.gif";
bottomfeedbackout.src="../default/i/feedback.gif";
toppreviousover.src="../default/i/h-previous.gif";
toppreviousout.src="../default/i/previous.gif";
bottompreviousover.src="../default/i/h-previous.gif";
bottompreviousout.src="../default/i/previous.gif";
topnextover.src="../default/i/h-next.gif";
topnextout.src="../default/i/next.gif";
bottomnextover.src="../default/i/h-next.gif";
bottomnextout.src="../default/i/next.gif";
topnextsectionout.src="../default/i/nextsection.gif";
topnextsectionover.src="../default/i/h-nextsection.gif";
bottomnextsectionout.src="../default/i/nextsection.gif";
bottomnextsectionover.src="../default/i/h-nextsection.gif";
}
function iOut(image)
{
if (browser=="N3")document[image].src=eval(image + "out.src");
}
function iOver(image)
{
if (browser=="N3")document[image].src=eval(image + "over.src");
}
// -->
</script><script src="../default/i/emailfriend.js" language="javascript"></script><a href="#navskip"><img border="0" alt="Skip to main content" src="../default/i/c.gif"></a><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#006699">
<td width="300">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#006699">
<td width="150"><img src="../default/i/mast_logo.gif" alt="IBM" width="160" height="47"></td>
<td width="150" background="../default/i/mgradient.gif"><font size="-2" color="#99ccff" face="Verdana, sans-serif"><b>&nbsp;</b></font><br><img src="../default/i/c.gif" width="150" height="1" alt=""></td>
</tr>
</table>
</td>
<td align="left" width="300">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><a href="http://www.ibm.com/shop1/"><img border="0" src="../default/i/shopibm.gif" width="100" height="25" alt="Shop"></a></td>
<td width="100"><a href="http://www.ibm.com/support/"><img border="0" src="../default/i/support.gif" width="100" height="25" alt="Support"></a></td>
<td width="100"><a href="http://www.ibm.com/download/"><img border="0" src="../default/i/downloads.gif" width="100" height="25" alt="Downloads"></a></td>
</tr>
</table>
</td>
</tr>
</table><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#000000">
<td>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#006699" width="150"><img src="../default/i/mast_lnav_sp.gif" width="150" height="21" alt=""></td>
<td colspan="4" bgcolor="#000000">
<table border="0" cellspacing="0" cellpadding="0" height="21">
<tr>
<td height="21" bgcolor="#000000" width="79" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/home/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>IBM Home</b></font></a></td>
<td bgcolor="#959595" width="1"><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
<td height="21" bgcolor="#000000" width="74" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/products/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>Products</b></font></a></td>
<td bgcolor="#959595" width="1"><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
<td height="21" bgcolor="#000000" width="81" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/services/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>Consulting</b></font></a></td>
<td bgcolor="#959595" width="1"><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
<td height="21" bgcolor="#000000" width="81" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/solutions/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>Industries</b></font></a></td>
<td bgcolor="#959595" width="1"><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
<td height="21" bgcolor="#000000" width="57" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/news/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>News</b></font></a></td>
<td bgcolor="#959595" width="1"><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
<td height="21" bgcolor="#000000" width="78" align="center"><a class="nav" style="color: #ffffff;" href="http://www.ibm.com/ibm/"><font size="-2" color="#ffffff" face="Verdana, sans-serif"><b>About IBM</b></font></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td bgcolor="#ffffff" height="1" width="150"><img src="../default/i/c.gif" width="150" height="1" alt=""></td>
</tr>
<tr>
<td bgcolor="#cc6633" height="3" width="150"><img src="../default/i/c.gif" width="150" height="3" alt=""></td>
</tr>
<tr>
<td bgcolor="#333333" height="1" width="150"><img src="../default/i/c.gif" width="150" height="1" alt=""></td>
</tr>
<tr>
<td bgcolor="#000000" height="1" width="150"><img src="../default/i/c.gif" width="150" height="1" alt=""></td>
</tr>
</table><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><font color="#006699" face="Verdana, sans-serif" size="-1"><a href="http://www.ibm.com/developer/">IBM developerWorks</a> : <a href="http://www.ibm.com/developer/xml/">XML</a> : <a href="http://www-106.ibm.com/developerworks/views/xml/tutorials.jsp">Education - Tutorials</a></font><br><img src="imagemaster/masthead.jpg" alt="XML Schema Infoset Model, Part 2"></td><td width="*" valign="bottom" align="right"><a border="0" href="os-schema2.zip"><img alt="ZIP" border="0" src="../default/i/icon-zip.gif"></a><a border="0" href="os-schema2-ltr.pdf"><img alt="PDF (letter)" border="0" src="../default/i/icon-pdf-ltr.gif"></a><a border="0" href="os-schema2-a4.pdf"><img alt="PDF (A4)" border="0" src="../default/i/icon-pdf-a4.gif"></a><a href="javascript:newWindow()" border="0"><img alt="e-mail" border="0" src="../default/i/icon-email.gif"></a></td></tr><tr><td height="2" colspan="2"><img height="2" width="1" src="../default/i/c.gif"></td></tr></table><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="150" height="1" bgcolor="#000000" colspan="6"><img alt="" height="1" width="150" src="../default/i/c.gif"></td></tr><tr><td background="../default/i/sw-gold.gif"><a border="0" href="index.html" onMouseOver="iOver('topmain'); iOver('bottommain'); self.status=mainblurb; return true;" onMouseOut="iOut('topmain'); iOut('bottommain'); self.status=''; return true;"><img alt="Main menu" border="0" src="../default/i/main.gif" name="topmain"></a></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topsection'); iOver('bottomsection'); self.status=sectionblurb; return true;" onMouseOut="iOut('topsection'); iOut('bottomsection'); self.status=''; return true;" href="index7.html"><img alt="Section menu" border="0" src="../default/i/section.gif" name="topsection"></a></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topfeedback'); iOver('bottomfeedback'); self.status=feedbackblurb; return true;" onMouseOut="iOut('topfeedback'); iOut('bottomfeedback'); self.status=''; return true;" href="os-schema2-9-3.html"><img alt="Feedback" border="0" src="../default/i/feedback.gif" name="topfeedback"></a></td><td width="100%" background="../default/i/sw-gold.gif"><img src="../default/i/c.gif"></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topprevious'); iOver('bottomprevious'); self.status=previousblurb; return true;" onMouseOut="iOut('topprevious'); iOut('bottomprevious'); self.status=''; return true;" href="os-schema2-7-1.html"><img alt="Previous" border="0" src="../default/i/previous.gif" name="topprevious"></a></td><td background="../default/i/sw-gold.gif"><img border="0" src="../default/i/xnext.gif"></td></tr><tr><td width="100%" colspan="5"></td><td width="108" height="1" bgcolor="#000000" align="right"><img alt="" height="1" width="108" src="../default/i/c.gif"></td></tr><tr><td colspan="5"></td><td align="right"><a border="0" onMouseOver="iOver('topnextsection'); iOver('bottomnextsection'); self.status=nextsectionblurb; return true;" onMouseOut="iOut('topnextsection'); iOut('bottomnextsection'); self.status=''; return true;" href="os-schema2-8-1.html"><img alt="Next Section" src="../default/i/nextsection.gif" border="0" name="topnextsection"></a></td></tr></table><table bgcolor="ffffff" cellspacing="0" cellpadding="2" border="0" height="400" width="100%"><tr valign="bottom"><td height="25" colspan="4"><img border="0" height="25" width="562" src="imagemaster/titlebar7.jpg" alt="7. Pulling it all together"></td></tr><tr><td bgcolor="ffffff" width="15">&nbsp;</td><td bgcolor="ffffff" width="12">&nbsp;</td><td valign="top" align="left" bgcolor="ffffff" width="*"><p><br><table cellspacing="0" cellpadding="0" border="0"><tr><td width="90%"><font size="4" face="Verdana, Arial, sans-serif"><b>Exercise 7 solution</b></font></td><td width="200" align="right"><font size="1" face="Verdana, Arial, sans-serif"><nobr> page 2 of 2</nobr></font></td></tr></table><br><br></p><font size="2" face="Verdana, Arial, sans-serif"><p>
</p><pre><font size="2" face="Courier New">
//Create the root schema
//Get the URI of the model file.
URI fileURI = URI.createPlatformResourceURI(xsdFile.getFullPath().toString());
//Create a resource set to manage the different resources
ResourceSet resourceSet = new ResourceSetImpl();
//Create a resource for this file.
Resource resource = resourceSet.createResource(fileURI);
XSDFactory xsdFactory = XSDFactory.eINSTANCE;
//Create the root XSDSchema object
XSDSchema schema = xsdFactory.createXSDSchema();
//set the schema for schema QName prefix to "xsd"
schema.setSchemaForSchemaQNamePrefix("xsd");
java.util.Map qNamePrefixToNamespaceMap = schema.getQNamePrefixToNamespaceMap();
//put the following namespace in the root schema namespace map
//xsd:http://www.w3.org/2001/XMLSchema
qNamePrefixToNamespaceMap.put(schema.getSchemaForSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
//We call updateElement to synchronize the MOF model with the underlying DOM model
//This should only have to be done after creating a new model
schema.updateElement();
//Add the root schema to the resource that was created above
resource.getContents().add(schema);
/**
* Create the global constructs
* Create Global Complex Type with name="PurchaseOrderType"
* Create Global Complex Type with name="USAddress"
* Create Global Complex Type with name="Items"
* Create Global Simple Type with name="SKU"
* Create Global Element with name="purchaseOrder" type="PurchaseOrderType"
* Create Global Element with name="comment" type="string"
*/
//Create Global Complex Type with name="PurchaseOrderType"
XSDComplexTypeDefinition poType = xsdFactory.createXSDComplexTypeDefinition();
poType.setName("PurchaseOrderType");
schema.getContents().add(poType);
//Create Global Complex Type with name="USAddress"
XSDComplexTypeDefinition usAddressType = xsdFactory.createXSDComplexTypeDefinition();
usAddressType.setName("USAddress");
schema.getContents().add(usAddressType);
//Create Global Complex Type with name="Items"
XSDComplexTypeDefinition itemsType = xsdFactory.createXSDComplexTypeDefinition();
itemsType.setName("Items");
schema.getContents().add(itemsType);
//Create Global Simple Type with name="SKU"
XSDSimpleTypeDefinition skuType = xsdFactory.createXSDSimpleTypeDefinition();
skuType.setName("SKU");
schema.getContents().add(skuType);
//Create Global Element with name="purchaseOrder" type="PurchaseOrderType"
XSDElementDeclaration poElement = xsdFactory.createXSDElementDeclaration();
poElement.setName("purchaseOrder");
poElement.setTypeDefinition(poType);
schema.getContents().add(poElement);
//Create Global Element with name="comment" type="string"
XSDElementDeclaration commentElement = xsdFactory.createXSDElementDeclaration();
commentElement.setName("comment");
XSDSimpleTypeDefinition stringType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"string");
commentElement.setTypeDefinition(stringType);
schema.getContents().add(commentElement);
/**
* Create the following contents under the PurchaseOrderType complex type
*
* &lt;xsd:complexType name="PurchaseOrderType"&gt;
* &lt;xsd:sequence&gt;
* &lt;xsd:element name="shipTo" type="USAddress" /&gt;
* &lt;xsd:element name="billTo" type="USAddress" /&gt;
* &lt;xsd:element ref="comment" minOccurs="0" /&gt;
* &lt;xsd:element name="items" type="Items" /&gt;
* &lt;/xsd:sequence&gt;
* &lt;xsd:attribute name="orderDate" type="xsd:date" /&gt;
* &lt;/xsd:complexType&gt;
*/
XSDParticle poSequenceParticle = xsdFactory.createXSDParticle();
XSDModelGroup poSeqeuence = xsdFactory.createXSDModelGroup();
poSeqeuence.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
poSequenceParticle.setContent(poSeqeuence);
poType.setContent(poSequenceParticle);
//Create local element name="shipTo" type="USAddress"
XSDElementDeclaration shipToElement = xsdFactory.createXSDElementDeclaration();
XSDParticle shipToParticle = xsdFactory.createXSDParticle();
shipToParticle.setContent(shipToElement);
shipToElement.setName("shipTo");
shipToElement.setTypeDefinition(usAddressType);
poSeqeuence.getContents().add(shipToParticle);
//Create local element name="billTo" type="USAddress"
XSDElementDeclaration billToElement = xsdFactory.createXSDElementDeclaration();
XSDParticle billToParticle = xsdFactory.createXSDParticle();
billToParticle.setContent(billToElement);
billToElement.setName("billTo");
billToElement.setTypeDefinition(usAddressType);
poSeqeuence.getContents().add(billToParticle);
//Create element ref="comment" minOccurs="0"
XSDElementDeclaration commentRef = xsdFactory.createXSDElementDeclaration();
XSDParticle commentRefParticle = xsdFactory.createXSDParticle();
commentRefParticle.setContent(commentRef);
commentRef.setResolvedElementDeclaration(commentElement);
commentRefParticle.setMinOccurs(0);
poSeqeuence.getContents().add(commentRefParticle);
//Create local element name="items" type="Items"
XSDElementDeclaration itemsElement = xsdFactory.createXSDElementDeclaration();
XSDParticle itemsParticle = xsdFactory.createXSDParticle();
itemsParticle.setContent(itemsElement);
itemsElement.setName("items");
itemsElement.setTypeDefinition(itemsType);
poSeqeuence.getContents().add(itemsParticle);
//Create local attribute name="orderDate" type="xsd:date"
XSDAttributeDeclaration orderDate = xsdFactory.createXSDAttributeDeclaration();
XSDAttributeUse orderDateUse = xsdFactory.createXSDAttributeUse();
orderDateUse.setContent(orderDate);
orderDate.setName("orderDate");
XSDSimpleTypeDefinition dateType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"date");
orderDate.setTypeDefinition(dateType);
poType.getAttributeContents().add(orderDateUse);
/**
* Create the following contents under the USAddress complex type
*
* &lt;xsd:complexType name="USAddress"&gt;
* &lt;xsd:sequence&gt;
* &lt;xsd:element name="name" type="xsd:string" /&gt;
* &lt;xsd:element name="street" type="xsd:string" /&gt;
* &lt;xsd:element name="city" type="xsd:string" /&gt;
* &lt;xsd:element name="state" type="xsd:string" /&gt;
* &lt;xsd:element name="zip" type="xsd:decimal" /&gt;
* &lt;/xsd:sequence&gt;
* &lt;xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US" /&gt;
* &lt;/xsd:complexType&gt;
*/
XSDParticle addressSequenceParticle = xsdFactory.createXSDParticle();
XSDModelGroup addressSeqeuence = xsdFactory.createXSDModelGroup();
addressSeqeuence.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
addressSequenceParticle.setContent(addressSeqeuence);
usAddressType.setContent(addressSequenceParticle);
//Create local element name="name" type="xsd:string"
XSDElementDeclaration nameElement = xsdFactory.createXSDElementDeclaration();
XSDParticle nameParticle = xsdFactory.createXSDParticle();
nameParticle.setContent(nameElement);
nameElement.setName("name");
nameElement.setTypeDefinition(stringType);
addressSeqeuence.getContents().add(nameParticle);
//Create local name="street" type="xsd:string"
XSDElementDeclaration streetElement = xsdFactory.createXSDElementDeclaration();
XSDParticle streetParticle = xsdFactory.createXSDParticle();
streetParticle.setContent(streetElement);
streetElement.setName("street");
streetElement.setTypeDefinition(stringType);
addressSeqeuence.getContents().add(streetParticle);
//Create local element name="city" type="xsd:string"
XSDElementDeclaration cityElement = xsdFactory.createXSDElementDeclaration();
XSDParticle cityParticle = xsdFactory.createXSDParticle();
cityParticle.setContent(cityElement);
cityElement.setName("city");
cityElement.setTypeDefinition(stringType);
addressSeqeuence.getContents().add(cityParticle);
//Create local element name="state" type="xsd:string"
XSDElementDeclaration stateElement = xsdFactory.createXSDElementDeclaration();
XSDParticle stateParticle = xsdFactory.createXSDParticle();
stateParticle.setContent(stateElement);
stateElement.setName("state");
stateElement.setTypeDefinition(stringType);
addressSeqeuence.getContents().add(stateParticle);
//Create local element name="zip" type="xsd:string"
XSDElementDeclaration zipElement = xsdFactory.createXSDElementDeclaration();
XSDParticle zipParticle = xsdFactory.createXSDParticle();
zipParticle.setContent(zipElement);
zipElement.setName("zip");
XSDSimpleTypeDefinition decimalType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"decimal");
zipElement.setTypeDefinition(decimalType);
addressSeqeuence.getContents().add(zipParticle);
//Create local attribute name="country" type="xsd:NMTOKEN" fixed="US"
XSDAttributeDeclaration countryAttribute = xsdFactory.createXSDAttributeDeclaration();
XSDAttributeUse countryUse = xsdFactory.createXSDAttributeUse();
countryUse.setContent(countryAttribute);
countryAttribute.setName("country");
XSDSimpleTypeDefinition nmtokenType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"NMTOKEN");
countryAttribute.setTypeDefinition(nmtokenType);
countryAttribute.setConstraint(XSDConstraint.FIXED_LITERAL);
countryAttribute.setLexicalValue("US");
usAddressType.getAttributeContents().add(countryUse);
/**
* Create the following contents under the Items complex type
* &lt;xsd:complexType name="Items"&gt;
* &lt;xsd:sequence&gt;
* &lt;xsd:element name="item" minOccurs="0" maxOccurs="unbounded"&gt;
* &lt;xsd:complexType&gt;
* &lt;xsd:sequence&gt;
* &lt;xsd:element name="productName" type="xsd:string" /&gt;
* &lt;xsd:element name="quantity"&gt;
* &lt;xsd:simpleType&gt;
* &lt;xsd:restriction base="xsd:positiveInteger"&gt;
* &lt;xsd:maxExclusive value="100" /&gt;
* &lt;/xsd:restriction&gt;
* &lt;/xsd:simpleType&gt;
* &lt;/xsd:element&gt;
* &lt;xsd:element name="USPrice" type="xsd:decimal" /&gt;
* &lt;xsd:element ref="comment" minOccurs="0" /&gt;
* &lt;xsd:element name="shipDate" type="xsd:date" minOccurs="0" /&gt;
* &lt;/xsd:sequence&gt;
* &lt;xsd:attribute name="partNum" type="SKU" use="required" /&gt;
* &lt;/xsd:complexType&gt;
* &lt;/xsd:element&gt;
* &lt;/xsd:sequence&gt;
* &lt;/xsd:complexType&gt;
*/
XSDParticle itemsSequenceParticle = xsdFactory.createXSDParticle();
XSDModelGroup itemsSeqeuence = xsdFactory.createXSDModelGroup();
itemsSeqeuence.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
itemsSequenceParticle.setContent(itemsSeqeuence);
itemsType.setContent(itemsSequenceParticle);
//Create local name="item" minOccurs="0" maxOccurs="unbounded"
XSDElementDeclaration itemElement = xsdFactory.createXSDElementDeclaration();
XSDParticle itemParticle = xsdFactory.createXSDParticle();
itemParticle.setContent(itemElement);
itemElement.setName("item");
itemParticle.setMinOccurs(0);
itemParticle.setMaxOccurs(-1);
itemsSeqeuence.getContents().add(itemParticle);
//Create anonymous complex type for the item local element
XSDComplexTypeDefinition itemAnonType = xsdFactory.createXSDComplexTypeDefinition();
itemElement.setAnonymousTypeDefinition(itemAnonType);
XSDParticle itemAnonTypeSequenceParticle = xsdFactory.createXSDParticle();
XSDModelGroup itemAnonTypeSeqeuence = xsdFactory.createXSDModelGroup();
itemAnonTypeSeqeuence.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
itemAnonTypeSequenceParticle.setContent(itemAnonTypeSeqeuence);
itemAnonType.setContent(itemAnonTypeSequenceParticle);
//Create local element name="productName" type="xsd:string"
XSDElementDeclaration productNameElement = xsdFactory.createXSDElementDeclaration();
XSDParticle productNameParticle = xsdFactory.createXSDParticle();
productNameParticle.setContent(productNameElement);
productNameElement.setName("productName");
productNameElement.setTypeDefinition(stringType);
itemAnonTypeSeqeuence.getContents().add(productNameParticle);
//Create local element name="quantity" with anon simpleType with restriction="xsd:positiveInteger"
//Create a maxExclusive facet on the anonymouse simple type with value="100"
XSDElementDeclaration quantityElement = xsdFactory.createXSDElementDeclaration();
XSDParticle quantityParticle = xsdFactory.createXSDParticle();
quantityParticle.setContent(quantityElement);
quantityElement.setName("quantity");
XSDSimpleTypeDefinition anonSimpleType = xsdFactory.createXSDSimpleTypeDefinition();
XSDSimpleTypeDefinition positiveIntegerType = schema.getSchemaForSchema().
resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"positiveInteger");
anonSimpleType.setBaseTypeDefinition(positiveIntegerType);
XSDMaxExclusiveFacet exclusiveFacet = xsdFactory.createXSDMaxExclusiveFacet();
exclusiveFacet.setLexicalValue("100");
anonSimpleType.getFacetContents().add(exclusiveFacet);
quantityElement.setAnonymousTypeDefinition(anonSimpleType);
itemAnonTypeSeqeuence.getContents().add(quantityParticle);
//Create local element name="USPrice" type="xsd:decimal
XSDElementDeclaration usPriceElement = xsdFactory.createXSDElementDeclaration();
XSDParticle usPriceParticle = xsdFactory.createXSDParticle();
usPriceParticle.setContent(usPriceElement);
usPriceElement.setName("USPrice");
usPriceElement.setTypeDefinition(decimalType);
itemAnonTypeSeqeuence.getContents().add(usPriceParticle);
//Create element ref="comment" minOccurs="0"
commentRef = xsdFactory.createXSDElementDeclaration();
commentRefParticle = xsdFactory.createXSDParticle();
commentRefParticle.setContent(commentRef);
commentRef.setResolvedElementDeclaration(commentElement);
commentRefParticle.setMinOccurs(0);
itemAnonTypeSeqeuence.getContents().add(commentRefParticle);
//Create local element name="shipDate" type="xsd:date" minOccurs="0"
XSDElementDeclaration shipDateElement = xsdFactory.createXSDElementDeclaration();
XSDParticle shipDateParticle = xsdFactory.createXSDParticle();
shipDateParticle.setContent(shipDateElement);
shipDateElement.setName("shipDate");
shipDateParticle.setMinOccurs(0);
shipDateElement.setTypeDefinition(dateType);
itemAnonTypeSeqeuence.getContents().add(shipDateParticle);
//Create local attribute name="partNum" type="SKU" use="required"
XSDAttributeDeclaration partNum = xsdFactory.createXSDAttributeDeclaration();
XSDAttributeUse partNumUse = xsdFactory.createXSDAttributeUse();
partNumUse.setContent(partNum);
partNum.setName("partNum");
partNum.setTypeDefinition(skuType);
partNumUse.setUse(XSDAttributeUseCategory.REQUIRED_LITERAL);
itemAnonType.getAttributeContents().add(partNumUse);
/**
* Create the following contents under the SKU simple type
* &lt;xsd:simpleType name="SKU"&gt;
* &lt;xsd:restriction base="xsd:string"&gt;
* &lt;xsd:pattern value="\d{3}-[A-Z]{2}" /&gt;
* &lt;/xsd:restriction&gt;
* &lt;/xsd:simpleType&gt;
*/
skuType.setBaseTypeDefinition(stringType);
//Create pattern facet value="\d{3}-[A-Z]{2}"
XSDPatternFacet pattern = xsdFactory.createXSDPatternFacet();
pattern.setLexicalValue("\\d{3}-[A-Z]{2}");
skuType.getFacetContents().add(pattern);
// Save the contents of the resource to the file system.
resource.save(Collections.EMPTY_MAP);
</font></pre><br></font></td></tr></table><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="right" colspan="6"><a border="0" onMouseOver="iOver('topnextsection'); iOver('bottomnextsection'); self.status=nextsectionblurb; return true;" onMouseOut="iOut('topnextsection'); iOut('bottomnextsection'); self.status=''; return true;" href="os-schema2-8-1.html"><img alt="Next Section" src="../default/i/nextsection.gif" border="0" name="bottomnextsection"></a></td></tr><tr><td width="100%" colspan="5"></td><td width="108" height="1" bgcolor="#000000" align="right"><img alt="" height="1" width="108" src="../default/i/c.gif"></td></tr><tr><td background="../default/i/sw-gold.gif"><a border="0" href="index.html" onMouseOver="iOver('topmain'); iOver('bottommain'); self.status=mainblurb; return true;" onMouseOut="iOut('topmain'); iOut('bottommain'); self.status=''; return true;"><img alt="Main menu" border="0" src="../default/i/main.gif" name="bottommain"></a></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topsection'); iOver('bottomsection'); self.status=sectionblurb; return true;" onMouseOut="iOut('topsection'); iOut('bottomsection'); self.status=''; return true;" href="index7.html"><img alt="Section menu" border="0" src="../default/i/section.gif" name="bottomsection"></a></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topfeedback'); iOver('bottomfeedback'); self.status=feedbackblurb; return true;" onMouseOut="iOut('topfeedback'); iOut('bottomfeedback'); self.status=''; return true;" href="os-schema2-9-3.html"><img alt="Feedback" border="0" src="../default/i/feedback.gif" name="bottomfeedback"></a></td><td width="100%" background="../default/i/sw-gold.gif"><img src="../default/i/c.gif"></td><td background="../default/i/sw-gold.gif"><a border="0" onMouseOver="iOver('topprevious'); iOver('bottomprevious'); self.status=previousblurb; return true;" onMouseOut="iOut('topprevious'); iOut('bottomprevious'); self.status=''; return true;" href="os-schema2-7-1.html"><img alt="Previous" border="0" src="../default/i/previous.gif" name="bottomprevious"></a></td><td background="../default/i/sw-gold.gif"><img border="0" src="../default/i/xnext.gif"></td></tr><tr><td width="150" height="1" bgcolor="#000000" colspan="6"><img alt="" height="1" width="150" src="../default/i/c.gif"></td></tr></table><style>
.bbg { background-color : #000000; vertical-align: middle }
a.mainlink:link { text-decoration: none; color: #ffffff; font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; }
a.mainlink:visited { text-decoration: none; color: #ffffff; font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; }
a.mainlink:hover { text-decoration: underline; color: #ffffff; font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; }
.divider { color: #999999; font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: normal; }
</style><table width="760" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><img src="../default/i/c.gif" width="1" height="1" alt=""></td>
</tr>
<tr valign="top">
<td height="21" class="bbg"><img src="../default/i/c.gif" width="1" height="1" alt=""> <a href="http://www-106.ibm.com/developerworks/cgi-bin/click.cgi?url=http://www.ibm.com/ibm/?origin=dwfooter" class="mainlink">About IBM</a><span class="divider"> | </span><a href="http://www-106.ibm.com/developerworks/cgi-bin/click.cgi?url=http://www.ibm.com/privacy/?origin=dwfooter" class="mainlink">Privacy</a><span class="divider"> | </span><a href="http://www-106.ibm.com/developerworks/cgi-bin/click.cgi?url=http://www.ibm.com/legal/?origin=dwfooter" class="mainlink">Legal</a><span class="divider"> | </span><a href="http://www-106.ibm.com/developerworks/cgi-bin/click.cgi?url=http://www.ibm.com/contact/?origin=dwfooter" class="mainlink">Contact</a></td>
</tr>
</table><script type="text/javascript" language="JavaScript1.2" src="//www.ibm.com/common/stats/stats.js"></script><noscript><img src="//i.ihost.com/i/c.gif" width="1" height="1" alt="" border="0"></noscript></body></html>