Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 381 Day 17. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard

Similar presentations


Presentation on theme: "COS 381 Day 17. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard"— Presentation transcript:

1 COS 381 Day 17

2 Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard Also @ http://perleybrook.umfk.maine.edu/SourceCode/http://perleybrook.umfk.maine.edu/SourceCode/ Html and XHTML examples http://perleybrook.umfk.maine.edu/samples/ In Class Work http://perleybrook.umfk.maine.edu/SourceCode/inclassWork/ Assignment 3 Not corrected Assignment 4 is posted Due April 4 Quiz 2 is not corrected One student has yet to take quiz Finish Discussion on XML

3 XML Schemas - Problems with DTDs: 1. Syntax is different from XML - cannot be parsed with an XML parser 2. It is confusing to deal with two different syntactic forms 3. DTDs do not allow specification of particular kinds of data XML Schemas is one of the alternatives to DTD - Two purposes: 1. Specify the structure of its instance XML documents 2. Specify the data type of every element and attribute of its instance XML documents DTD can be converted to schemas http://www.hitsw.com/xml_utilites/ Resource http://www.w3.org/XML/Schema

4 - Schemas are written using a namespace: - http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema -- Every XML schema has a single root, schema - The schema element must specify the namespace for schemas as its xmlns:xsd attribute - Every XML schema itself defines a tag set, which must be named targetNamespace = http://cs.uccs.edu/planeSchema For this class http://perleybrook.umfk.maine.edu/ “home directory” If we want to include nested elements, we must set the elementFormDefault attribute to qualified - The default namespace must also be specified xmlns = "http://cs.uccs.edu/planeSchema" XML Schemas (continued)

5 - - A complete example of a schema element: <xsd:schema <xmlns:xsd = "http://www.w3.org/2001/XMLSchema" <targetNamespace ="http://cs.uccs.edu/planeSchema" xmlns = "http://cs.uccs.edu/planeSchema" elementFormDefault = "qualified"> XML Schemas (continued)

6 - - A complete example of a schema element: <schema <xmlns = "http://www.w3.org/2001/XMLSchema" <targetNamespace ="http://cs.uccs.edu/planeSchema" xmlns:planes = "http://cs.uccs.edu/planeSchema" elementFormDefault = "qualified"> XML Schemas (continued)

7 - Defining an instance document - The root element must specify the namespaces it uses 1. The default namespace 2. The standard namespace for instances ( XMLSchema-instance ) 3. The location where the default namespace is defined, using the schemaLocation attribute, which is assigned two values <planes xmlns = "http://cs.uccs.edu/planeSchema" xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://cs.uccs.edu/planeSchema planes.xsd" > Data Type Categories 1. Simple (strings only, no attributes and no nested elements) 2. Complex (can have attributes and nested elements) XML Schemas (continued)

8 - XMLS defines over 40 data types http://www.w3.org/TR/xmlschema-2/#built-in-datatypes - Primitive: string, Boolean, float, … - Derived: byte, decimal, positiveInteger, … - User-defined (derived) data types – specify constraints on an existing type (the base type) - Constraints are given in terms of facets ( totalDigits, maxInclusive, etc.) - Both simple and complex types can be either named or anonymous - DTDs define global elements (context is irrelevant) - With XMLS, context is essential, and elementscan be either: 1. Local, which appears inside an element that is a child of schema, or 2. Global, which appears as a child of schema XML Schemas (continued)

9 - Defining a simple type: - Use the element tag and set the name and type attributes <xsd:element name = "bird" type = "xsd:string" /> - An instance could have: Yellow-bellied sap sucker - Element values can be constant, specified with the fixed attribute fixed = "three-toed" - User-Defined Types - Defined in a simpleType element, using facets specified in the content of a restriction element - Facet values are specified with the value attribute XML Schemas (continued)

10 - Categories of Complex Types 1. Element-only elements (elements no text) 2. Text-only elements (text no elements) 3. Mixed-content elements (both text and elements 4. Empty elements - Element-only elements - Defined with the complexType element - Use the sequence tag for nested elements that must be in a particular order - Use the all tag if the order is not important XML Schemas (continued)

11 - Nested elements can include attributes that give the allowed number of occurrences ( minOccurs, maxOccurs, unbounded ) - We can define nested elements elsewhere XML Schemas (continued)

12 - The global element can be referenced in the complex type with the ref attribute - Validating Instances of XML Schemas - Can be done with several different tools - One of them is xsv, which is available from: http://www.ltg.ed.ac.uk/~ht/xsv-status.html - Note: If the schema is incorrect (bad format), xsv reports that it can find the schema planes.xsd Plane.xml XML Schemas (continued)

13 Modified Plane example from text <!-- plane.xml A simple XML document for illustrating a schema The schema is in planes.xsd --> <plane xmlns = "http://perleybrook.umfk.maine.edu/examples/planes" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://perleybrook.umfk.maine.edu/examples/planes planes.xsd"> Cessna Piper Beechcraft

14 Con’t <!-- planes.xsd A simple schema for plane.xml --> <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" targetNamespace = "http://perleybrook.umfk.maine.edu/examples/planes" xmlns = "http://perleybrook.umfk.maine.edu/examples/planes" elementFormDefault = "qualified"> <xsd:element name = "make" type = "xsd:string" minOccurs = "1" maxOccurs = "unbounded" />

15 Validating Instances of Schemas Various systems for validating instances against schemas Online http://www.w3.org/2001/03/webdata/xsvhttp://www.w3.org/2001/03/webdata/xsv XML support libraries include validation: Xerces from Apache, Saxon, Altova XML tools Some IDE’s have automatic validation: Altova Spy, Eclipse with Oxygen, Eclipse with XML Buddy Pro Certain IDE’s will use schemas to provide support for XML file creation

16 Displaying Raw XML Documents - There is no presentation information in an XML document - An XML browser should have a default style sheet for an XML document that does not specify one - You get a stylized listing of the XML

17 - A CSS style sheet for an XML document is just a list of its tags and associated styles - The connection of an XML document and its style sheet is made through an xml-stylesheet processing instruction <?xml-stylesheet type = "text/css" href = "mydoc.css"?> --> SHOW planescss.xml and planes.css planescss.xmlplanes.css Displaying XML Documents with CSS

18 7.9 Overview of XSLT A functional style programming language Basic syntax is XML There is some similarity to LISP and Scheme An XSLT processor takes an XML document as input and produces output based on the specifications of an XSLT document

19 8.9 XSLT Style Sheets Resources http://www.w3.org/Style/XSL/ http://www.vbxml.com/xsl/tutorials/intro/default.asp http://www.w3.org/TR/xsl/ -An XSLT processor merges an XML document into an XSLT style sheet - This merging is a template-driven process - An XSLT style sheet can specify page layout, page orientation, writing direction, margins, page numbering, etc.

20 7.9 XSLT Style Sheets A family of specifications for transforming XML documents XSLT: specifies how to transform documents XPath: specifies how to select parts of a document and compute values XSL-FO: specifies a target XML language describing the printed page XSLT describes how to transform XML documents into other XML documents such as XHTML XSLT can be used to transform to non-XML documents as well

21 Figure 7.5 XSLT processing

22 7.9 XSLT Structure An XSLT document contains templates XPath is used to specify patterns of elements to which the templates should apply The content of a template specifies how the matched element should be processed The XSLT processor will look for parts of the input document that match a template and apply the content of the template when a match is found Two models Template-driven works with highly regular data Data-driven works with more loosely structured data with a recursive structure (like XHTML documents)

23 - The processing instruction we used for connecting a CSS style sheet to an XML document is used to connect an XSLT style sheet to an XML document - An example: <?xml-stylesheet type = "text/xsl" href = "xslplane.xsl" ?> 1977 Cessna Skyhawk Light blue and white XSLT Style Sheets (continued)

24 - An XSLT style sheet is an XML document with a single element, stylesheet, which defines namespaces <xsl:stylesheet xmlns:xsl = http://www.w3.org/1999/XSL/Formathttp://www.w3.org/1999/XSL/Format xmlns = “http://www.w3.org/1999/xhtml”> - If a style sheet matches the root element of the XML document, it is matched with the template: - A template can match any element, just by naming it (in place of / ) - XSLT elements include two different kinds of elements, those with content and those for which the content will be merged from the XML doc - Elements with content often represent xHTML elements Happy Easter! XSLT Style Sheets (continued)

25 - XSLT elements that represent xHTML elements are simply copied to the merged document - The XSLT value-of element - Has no content - Uses a select attribute to specify part of the XML data to be merged into the XSLT document - The value of select can be any branch of the document tree  SHOW xslplane.xml xslplane.xslxslplane.xml xslplane.xsl - The XSLT for-each element - Used when an XML document has a sequence of the same elements --> SHOW xslplanes.xml xslplanes.xml --> SHOW xslplanes.xsl xslplanes.xsl XML Transformations and Style Sheets (continued)

26 7.9 Producing Transformation Output Elements not belonging to XSLT and other text will be copied to the output when the containing template is applied The value-of tag causes the select attribute value to be evaluated and the result is put into the output The value of an element is the text contained in it and in sub- elements The value of an attribute is the value Example xslplane1.xsl transforms the xslplane.xml file into XHTML for display purposesxslplane1.xsl xslplane.xml If the style sheet is in the same directory as the XML file, some browsers will pick up the transformation and apply it This works with Firefox and Internet Explorer but not Opera

27 7.9 Processing Repeated Elements File xslplanes.xml contains data about multiple airplanesxslplanes.xml The style sheet xslplanes.xsl uses a for-each element to process each plane element in the source documentxslplanes.xsl A sort element could be included to sort output The element Specifies sorting by year

28 Overview

29 7.10 XML Processors XML processors provide tools in programming languages to read in XML documents, manipulate them and to write them out

30 7.10 Purposes of XML Processors Four purposes Check the basic syntax of the input document Replace entities Insert default values specified by schemas or DTD’s If the parser is able and it is requested, validate the input document against the specified schemas or DTD’s The basic structure of XML is simple and repetitive, so providing library support is reasonable Examples Xerces-J from the Apache foundation provides library support for Java Command line utilities are provided for checking well-formedness and validity Two different standards/models for processing SAX DOM

31 7.10 Parsing The process of reading in a document and analyzing its structure is called parsing The parser provides as output a structured view of the input document

32 7.10 The SAX Approach In the SAX approach, an XML document is read in serially As certain conditions, called events, are recognized, event handlers are called The program using this approach only sees part of the document at a time

33 7.10 The DOM Approach In the DOM approach, the parser produces an in- memory representation of the input document Because of the well-formedness rules of XML, the structure is a tree Advantages over SAX Parts of the document can be accessed more than once The document can be restructured Access can be made to any part of the document at any time Processing is delayed until the entire document is checked for proper structure and, perhaps, validity One major disadvantage is that a very large document may not fit in memory entirely

34 7.11 Web Services Allow interoperation of software components on different systems written in different languages Servers that provide software services rather than documents Remote Procedure Call DCOM and CORBA provide implementations DCOM is Microsoft specific CORBA is cross-platform

35 7.11 Web Service Protocols Three roles in web services Service providers Service requestors Service registry The Web Services Definition Language provides a standard way to describe services The Universal Description, Discovery and Integration service provides a standard way to provide information about services in response to a query SOAP is used to specify requests and responses


Download ppt "COS 381 Day 17. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard"

Similar presentations


Ads by Google