DOC PREVIEW
CMU ISM 95733 - More XML Schema

This preview shows page 1-2-17-18-19-35-36 out of 36 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

More XML SchemaPowerPoint PresentationSlide 3Slide 4Slide 5Slide 6Slide 7Slide 8A Simple Purchase OrderSlide 10Purchase Order XSDLSlide 12Slide 13Slide 14Slide 15Slide 16Comments in XSDLElement DefinitionsSlide 19Simple ContentComplex ContentPlace Holder Element DefinitionsSlide 23Occurrence optionsChoices And a New ExampleSlide 26Slide 27Slide 28Slide 29ChoicesSlide 31Embedded GroupsMixed ContentAttributesSlide 35Attribute TypesInternet Technologies 1More XML Schema • The main source for these slides is “The XML Companion” by Bradley• Other resources: http://www.w3.org/TR/xmlschema-2/Internet Technologies 2Three Major Uses – Same as DTD’s1. Validation 2. Code Generation3. CommunicationInternet Technologies 3Better than DTD’s•Good support for namespaces (namespaces came after DTD’s)•Type Checking (DTD’s use #PCDATA) See next slide•XML Syntax (DTD’s are not XML)•XML tools, like editors, will work with XSDLInternet Technologies 4From W3CXML SchemaPart 2DataTypesInternet Technologies 5// Validate.java using Xerces// Program written by Kunal Kavirajimport java.io.*;import org.xml.sax.ErrorHandler;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.InputSource;import org.xml.sax.helpers.XMLReaderFactory;import org.xml.sax.helpers.DefaultHandler;Internet Technologies 6public class Validate implements ErrorHandler{ public static boolean valid = true; public static void main (String argv []) throws SAXException, IOException { if (argv.length != 1) { System.err.println ("Usage: java Validate filename.xml"); System.exit (1); } // get a parserInternet Technologies 7XMLReader reader = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser"); // request validation reader.setFeature("http://xml.org/sax/features/validation", true); reader.setFeature( "http://apache.org/xml/features/validation/schema",true); reader.setErrorHandler(new Validate()); // associate an InputSource object with the file name InputSource inputSource = new InputSource(argv[0]); // go ahead and parse reader.parse(inputSource); System.out.println("Valid Document is " + valid); }Internet Technologies 8public void warning(SAXParseException exception) { System.out.println("Validate:Warning" + exception); valid = false; } public void error(SAXParseException exception) { System.out.println("Validate:Error" + exception); valid = false; } public void fatalError(SAXParseException exception) { System.out.println("Validate:fatalError" + exception); valid = false; }}Internet Technologies 9A Simple Purchase Order<?xml version="1.0" encoding="UTF-8"?> <!-- po.xml --><purchaseOrder orderDate="07.23.2001" xmlns="http://www.cds-r-us.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cds-r-us.com po.xsd">Internet Technologies 10 <recipient country="USA"> <name>Dennis Scannel</name> <street>175 Perry Lea Side Road</street> <city>Waterbury</city> <state>VT</state> <postalCode>15216</postalCode> </recipient> <order> <cd artist="Brooks Williams" title="Little Lion" /> <cd artist="David Wilcox" title="What you whispered" /> </order></purchaseOrder>Internet Technologies 11Purchase Order XSDL<?xml version="1.0" encoding="utf-8"?> <!-- po.xsd --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cds-r-us.com" targetNamespace="http://www.cds-r-us.com" > XSDL StandardnamespaceTarget namespaceInternet Technologies 12<xs:element name="purchaseOrder"> <xs:complexType> <xs:sequence> <xs:element ref="recipient" /> <xs:element ref="order" /> </xs:sequence> <xs:attribute name="orderDate" type="xs:string" /> </xs:complexType> </xs:element>Internet Technologies 13<xs:element name = "recipient"> <xs:complexType> <xs:sequence> <xs:element ref="name" /> <xs:element ref="street" /> <xs:element ref="city" /> <xs:element ref="state" /> <xs:element ref="postalCode" /> </xs:sequence> <xs:attribute name="country" type="xs:string" /> </xs:complexType> </xs:element>Internet Technologies 14 <xs:element name = "name" type="xs:string" /> <xs:element name = "street" type="xs:string" /> <xs:element name = "city" type="xs:string" /> <xs:element name = "state" type="xs:string" /> <xs:element name = "postalCode" type="xs:short" /> <xs:element name = "order"> <xs:complexType> <xs:sequence> <xs:element ref="cd" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element>Internet Technologies 15 <xs:element name="cd"> <xs:complexType> <xs:attribute name="artist" type="xs:string" /> <xs:attribute name="title" type="xs:string" /> </xs:complexType> </xs:element></xs:schema>Internet Technologies 16D:..\95-733\examples\XSDL\testing>java Validate po.xmlValid Document is trueInternet Technologies 17Comments in XSDL<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cds-r-us.com" targetNamespace="http://www.cds-r-us.com" > <xs:annotation> <xs:documentation>This is a comment. </xs:documentation> </xs:annotation>::Internet Technologies 18Element Definitions•The Element element is used to define an element•The Element element may be empty <xs:element name = "name" type="xs:string" />•Or, may contain content<xs:element name="cd"> <xs:complexType> <xs:attribute name="artist" type="xs:string" /> <xs:attribute name="title" type="xs:string" /> </xs:complexType> </xs:element>Internet Technologies 19Element Definitions•The Element element may be empty and contain no other attributes <xs:element name = "purchaseOrder"/>•This purchaseOrder element may contain anything (more elements and text)•DTD <!ELEMENT purchaseOrder ANY>Internet Technologies 20Simple Content•An element may


View Full Document

CMU ISM 95733 - More XML Schema

Download More XML Schema
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view More XML Schema and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view More XML Schema 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?