Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ertan Deniz Instructor.  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)

Similar presentations


Presentation on theme: "Ertan Deniz Instructor.  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)"— Presentation transcript:

1 Ertan Deniz Ertan.deniz70@gmail.com Instructor

2  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)

3  Portions of this lecture are derived from in “Web Services: Principles and Technology” by Michael P. Papazoglou and its accompanying instructors materials, © Pearson Education Limited 2008.

4 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008  XML schema refers to a document that defines the content of and structure for expressing XML documents.  Schema is commonly used in the area of databases to refer to the logical structure of a database.  Schemas provide support for additional meta-data characteristics such as structural relationships, cardinality, valid values, and data types.  Each type of schema acts as a method of describing data characteristics and applying rules and constraints to a referencing XML document.  An XML schema describes the elements and attributes that may be contained in a schema conforming document and the ways that the elements may be arranged within a document structure.

5 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008 Sophie Jones 34 File “Person.xml” <xs:element name="Last“ type="xs:string"/> File “Person.xsd”

6 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008  Annotation (Schema Comment)  Element Name, Type  Simple Type (Int, String)  Complex Type  MinOccurs,MaxOccurs  Attribute Name,Type  Sequence (Specifies the exact Order)  Choice ( Any one, but not at all)  All (All required, any order)  Extension,Restriction

7 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008 One item of a purchase order with its details Needs to be specified in US$ Elements and their content modelElements and their content model

8 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008 Attributesand Attribute Groups Attributes and Attribute Groups

9 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008

10 < xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:PO="http://www.plastics_supply.com/PurchaseOrder" targetNamespace="http://www.plastics_supply.com/PurchaseOrder"> Michael P. Papazoglo u, Web Services, 1 st Edition, © Pearson Education Limited 2008

11

12 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008 <xsd:element name="shippingAddress" type="PO:Address" minOccurs= "1" maxOccurs="1"/> <xsd:element name="billingAddress" type="PO:Address" minOccurs= "1" maxOccurs="1"/> </xsd:complexType Variant of the PurchaseOrder type that uses the base type Address for its billingAddress and shippingAddress elements.

13 Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008 Plastic Products 459 Wickham st. Fortitude Valley QLD 4006 Australia 158 Edward st. QLD 4000 Australia 2002-09-15 An instance document can now use any type derived from base type Address for its billingAddress and shippingAddress elements. PurchaseOrder type uses the derived AustralianPostalAddress type as its billingAddress and the derived AustralianAddress type as its shippingAddress elements.

14  XML Schemas  Document Navigation (Xpath)  Document Transformation (XSLT)

15  XPath is a standard for developing expressions that can be used to find specific pieces of information within an XML document.  XPath is an abstract language that defines a tree model that codifies the logical structure of an XML document against which all expressions are evaluated.  selects nodes in an XML document Michael P. Papazoglou, Web Services, 1 st Edition, © Pearson Education Limited 2008

16 Kenneth M.Anderson, CSCI 7818 Lecture

17  Example Xpath  gradebook/student/grade  is an XPath expression that selects all “grade” nodes in the example on the previous slide  XPath can even select attributes  gradebook/student/grade[@name=“hw3”]  More Examples  //grade “start at the root node and find all grade nodes”  gradebook/student[2] “select the second student node under gradebook” Kenneth M.Anderson, CSCI 7818 Lecture

18  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)

19  XSLT stands for XML Stylesheet Language, Transformations  XML is primarily used to describe and contain data. Although the most obvious and effective use of XML is to describe data, the eXtensible Stylesheet Language Transform (XSLT) can also be used to format or transform XML content for presentation to users.  The XSLT process transforms an XML structure into presentation technology such as HTML or into any other required forms and structures.  XSLT uses the XML Path Language (Xpath) to address and locate sections of XML documents. Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008

20  XSLT was developed as part of the XML stylesheet standards effort  What’s a stylesheet?  A stylesheet is a device for specifying presentation information independent of content  Stylesheets in HTML  The Web already has a stylesheet language called “cascading stylesheets” or CSS  Specifies mechanisms for transforming XML to other structures  XML->XML  XML->HTML  XML->PDF Kenneth M.Anderson, CSCI 7818 Lecture

21  To understand XSLT, you must view XML documents as tree structures  XSLT provides rules to transform one tree into another tree  It traverses the source tree in an order dictated by the stylesheet and generates the destination tree using the rules of the stylesheet Kenneth M.Anderson, CSCI 7818 Lecture

22  XSLT transforms XML documents using stylesheets that are themselves XML documents  All XSLT stylesheets have the following form <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> …templates and transformation rules go here… Kenneth M.Anderson, CSCI 7818 Lecture

23  Stylesheets consist of templates that “match” nodes of the source XML tree (i.e. document)  Each template then specifies what should be generated in the destination tree (or document)  Match="/" Associates the template with the root of the XML source document  A template looks like this: Grade Book Kenneth M.Anderson, CSCI 7818 Lecture

24

25  Stylesheet processing XSLT processor is handed a document and a stylesheet  It starts a (breadth-first) traversal at the root node and checks to see if there is a template match  If so, it applies the template and looks for an “xsl:apply-templates” element If such an element exists, it continues the traversal if no such element exists, the traversal stops  If not, it traverses down the tree looking for a template match with some other node of the tree Kenneth M.Anderson, CSCI 7818 Lecture

26  The apply-templates tag determines if an XSLT processor continues traversing a document once a template match has occurred  The apply-templates tag can contain an attribute called “select” which can specify the specific children to continue traversing using an XPath expression  All children traversed  All grade nodes with a name attribute equal to “HW4” traversed (any other nodes skipped during the subsequent traversal) Kenneth M.Anderson, CSCI 7818 Lecture

27 Do something here...  The select attribute is an Xpath expression that selects the nodes to iterate over Kenneth M.Anderson, CSCI 7818 Lecture

28 Grade Book Grade: Kenneth M.Anderson, CSCI 7818 Lecture

29 Grade Book Grade: 10 Grade: 7 Grade: 6 Grade: 10 … more grades here... Kenneth M.Anderson, CSCI 7818 Lecture Grade Book  Grade: 10  Grade: 7  Grade: 6  Grade: 10 HTML Result

30 Kenneth M.Anderson, CSCI 7818 Lecture  <xsl:when test = “position()=last()”> Do something for last element <xsl:when test = “position()=first()”> Do something for first element Do something for other elements

31 Kenneth M.Anderson, CSCI 7818 Lecture  This selects all student nodes, sorts them by name, and then applies templates to them

32  We can not cover entire standards  Xpath Standard http://www.w3.org/TR/xpath  XSLT Standard Reference http://www.w3.org/TR/xslt/  XSLT General http://www.xslt.com/  Online XSLT Sample http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdc atalog&xsltfile=cdcatalog http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdc atalog&xsltfile=cdcatalog  Reference on XSLT http://www.zvon.org/xxl/XSLTreference/Output/index. html Kenneth M.Anderson, CSCI 7818 Lecture

33  Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008. (Book Slides)  Kenneth M.Anderson, CSCI 7818 – XSLT Overview http://www.cs.colorado.edu/~kena/classes/7818/f08/lectures/lecture_2_xslt_ overview.pdf http://www.cs.colorado.edu/~kena/classes/7818/f08/lectures/lecture_2_xslt_ overview.pdf  XSLT ve Xpath resources http://www.w3schools.com .NET XML Tools Tutorial .NET Xpath Sample (Code Project) http://www.codeproject.com/KB/XML/gsxpathtutorial.aspx

34 Thanks for your interest...


Download ppt "Ertan Deniz Instructor.  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)"

Similar presentations


Ads by Google