DOC PREVIEW
CMU ISM 95733 - Lecture

This preview shows page 1-2-3-4-30-31-32-33-34-61-62-63-64 out of 64 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 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 64 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

XML SchemaSlide 2XSDL Alternatives IncludeXSDL - A Simple Purchase OrderSlide 5Purchase Order XSDLSlide 7Slide 8Slide 9Slide 10Three Major Uses – Same as DTD’sBetter than DTD’sValidate.javaSlide 14Slide 15Slide 16Slide 17XML DocumentXSDL Grammar itemList.xsdSlide 20Slide 21Purchase again (with Prefixes)Slide 23Slide 24XSDL Grammar po.xsdSlide 26Slide 27Slide 28Running ValidateFix the error and run againSlide 31Introduce a Namespace ErrorSlide 33Slide 34And run validateCode GenerationitemList.xsd againSlide 38Run xjcSlide 40The Ant build script used for these examples is also XMLSlide 42Slide 43More details on XML SchemasComments in XSDLElement DefinitionsSlide 47Simple ContentComplex ContentPlace Holder Element DefinitionsSlide 51Occurrence optionsChoices And a New ExampleSlide 54Slide 55Slide 56Slide 57ChoicesSlide 59Embedded GroupsMixed ContentAttributesSlide 63Attribute TypesInternet Technologies 1XML Schema The main source for these slides is “The XML Companion” by Bradley Other resources: http://www.w3.org/TR/xmlschema-2/Internet Technologies 2XML Schema• “XML Schema” is the official name• XSDL (XML Schema Definition Language) is the language used to create schema definitions• Can be used to more tightly constrain a document instance• Supports namespaces• Permits type derivationInternet Technologies 3XSDL Alternatives Include•DTD’s•RELAX •TREX (James Clark - Tree Regular Expressions for XML)•RELAX NG (RELAX and TREX combined to Relax Next Generation)•Schematron (“Rule based” rather than “grammar based” see www.ascc.net/xml/schematron) Based on XSLT and XPathInternet Technologies 4XSDL - A 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 5<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 6Purchase 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" >Internet Technologies 7<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 8<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 9<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 10<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 11Three Major Uses – Same as DTD’s1. Validation2. Code Generation3. CommunicationInternet Technologies 12Better than DTD’s•Good support for namespaces•Type Checking•XML SyntaxBut Harder than DTD’sInternet Technologies 13Validate.java// Validate.java using Xercesimport 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;import java.io.*;Internet Technologies 14import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.SAXException;import org.xml.sax.InputSource;import org.xml.sax.SAXParseException;Internet Technologies 15public class Validate extends DefaultHandler { public static boolean valid = true; public void error(SAXParseException exception) { System.out.println("Received notification of a recoverable error." + exception); valid = false; } public void fatalError(SAXParseException exception) { System.out.println("Received notification of a non-recoverable error."+ exception); valid = false; } public void warning(SAXParseException exception) { System.out.println("Received notification of a warning."+ exception); }16public static void main (String argv []) { if (argv.length != 1) { System.err.println ("Usage: java Validate filename.xml"); System.exit (1); } try { // get a parser XMLReader 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);Internet Technologies 17} catch(org.xml.sax.SAXException e) { System.out.println("Error in parsing " + e); valid = false; } catch(java.io.IOException e) { System.out.println("Error in I/O " + e); System.exit(0); }


View Full Document

CMU ISM 95733 - Lecture

Download Lecture
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 Lecture 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 Lecture 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?