Extensible Markup and Beyond September 26, 2001 Jeff Derstadt

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
XML: Extensible Markup Language
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
Introduction to XSLT. What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
Tutorial 11 Creating XML Document
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
4/20/2017.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 XML Taken from Chapter 7.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
XML – Extensible Markup Language XML eXtensible – add to language. Markup – delimit info using tags. Language – a way to express info.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
CSE3201/CSE4500 Information Retrieval Systems
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
Extensible Markup and Beyond
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
These Questions are copied from
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
ITB Web programming for E- Commerce 1 ITB6227 Programming for E-COMMERCE Lecture Presentation of XML Documents.
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
Unit 10 Schema Data Processing. Key Concepts XML fundamentals XML document format Document declaration XML elements and attributes Parsing Reserved characters.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML 1.Introduction to XML 2.Document Type Definition (DTD) 3.XML Parser 4.Example: CGI Gateway to XML Middleware.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Extensible Markup Language (XML) Pat Morin COMP 2405.
.
XSLT: The XML transformation language
XML: Extensible Markup Language
XML Introduction Bill Jerome.
Unit 4 Representing Web Data: XML
XML in Web Technologies
Extensible Markup Language XML
Chapter 7 Representing Web Data: XML
Applying eXtensible Style Sheets (XSL)
Overview XML DTD, XML Schema Xpath, XQuery Xslt
XML WITH CSS.
More XML XML schema, XPATH, XSLT
Unit 6 - XML Transformations
Presentation transcript:

Extensible Markup and Beyond September 26, 2001 Jeff Derstadt CS 433 Xml, DTD, XPath, & Xslt Extensible Markup and Beyond September 26, 2001 Jeff Derstadt

Administration Due: Friday Sept. 28th Logging into Egret Questions? Relational table creation and summary See course web site for more details Logging into Egret Questions?

Overview Xml DTD XPath Xslt A self-describing, hierarchal data model Standardizing schemas for Xml XPath How to navigate and query Xml documents Xslt How to transform one Xml document into another Xml document

Xml – An Example <class name=‘CS 433’> <location building=‘Olin’ room=‘255’/> <professor>Johannes Gehrke</professor> <ta>Jeff</ta> <student_list> <student id=‘999-991’>John Smith</student> <student id=‘999-992’>Jane Doe</student> </student_list> </class>

Xml – Extensible Markup Language A way of communicating information Markup Notes or meta-data that describe your data or language Extensible Limitless ability to define new languages or data sets

Xml – What’s The Point? You can include your data and a description of what the data represents This is useful for defining your own language or protocol Example: Chemical Markup Language <molecule> <weight>234.5</weight> <Spectra>…</Spectra> <Figures>…</Figures> </molecule>

Xml – Structure Xml looks like HTML Xml is a hierarchy of user-defined tags called elements with attributes and data Data is described by elements, elements are described by attributes <student id=‘999-991’>John Smith</student> attribute attribute value data closing tag open tag element name

Xml – Elements <student id=‘999-991’>John Smith</student> Xml is case and space sensitive Element opening and closing tag names must be identical Opening tags: “<” + element name + “>” Closing tags: “</” + element name + “>” Empty Elements have no data and no closing tag: They begin with a “<“ and end with a “/>” <location/> attribute data closing tag open tag element name attribute value

Xml – Attributes <student id=‘999-991’>John Smith</student> Attributes provide additional information for element tags. There can be zero or more attributes in every element; each one has the the form: attribute_name=‘attribute_value’ There is no space between the name and the “=‘” Attribute values must be surrounded by “ or ‘ characters Multiple attributes are separated by white space (one or more spaces or tabs). open tag element name attribute attribute value data closing tag

Xml - Data <student id=‘999-991’>John Smith</student> Xml data is any information between an opening and closing tag Xml data must not contain the ‘<‘ or ‘>’ characters open tag element name attribute attribute value data closing tag

Xml – Nesting & Hierarchy Xml tags can be nested in a tree hierarchy Xml documents can have only one root tag Between an opening and closing tag you can insert: 1. Data 2. More Elements 3. A combination of data and elements <root> <tag1> Some Text <tag2>More</tag2> </tag1> </root>

Xml – Storage Storage is done just like an n-ary tree (DOM) <root> <tag1> Some Text <tag2>More</tag2> </tag1> </root> Node Type: Element_Node Name: Element Value: Root Node Type: Element_Node Name: Element Value: tag1 Node Type: Element_Node Name: Element Value: tag2 Type: Text_Node Name: Text Value: Some Text Node Type: Text_Node Name: Text Value: More

Xml vs. Relational Model <Table> <Computer Id=‘101’> <Speed>800Mhz</Speed> <RAM>256MB</RAM> <HD>40GB</HD> </Computer> <Computer Id=‘102’> <Speed>933Mhz</Speed> <RAM>512MB</RAM> </Table> Computer Table Id Speed RAM HD 101 800Mhz 256MB 40GB 102 933Mhz 512MB

DTD – Document Type Definition A DTD is a schema for Xml data Xml protocols and languages can be standardized with DTD files A DTD says what elements and attributes are required or optional Defines the formal structure of the language

DTD – An Example <Basket> <Cherry flavor=‘good’/> <?xml version='1.0'?> <!ELEMENT Basket (Cherry+, (Apple | Orange)*) > <!ELEMENT Cherry EMPTY> <!ATTLIST Cherry flavor CDATA #REQUIRED> <!ELEMENT Apple EMPTY> <!ATTLIST Apple color CDATA #REQUIRED> <!ELEMENT Orange EMPTY> <!ATTLIST Orange location ‘Florida’> -------------------------------------------------------------------------------- <Basket> <Cherry flavor=‘good’/> <Apple color=‘red’/> <Apple color=‘green’/> </Basket> <Basket> <Apple/> <Cherry flavor=‘good’/> <Orange/> </Basket>

DTD - !ELEMENT <!ELEMENT Basket (Cherry+, (Apple | Orange)*) > !ELEMENT declares an element name, and what children elements it should have Wildcards: * Zero or more + One or more Name Children

DTD - !ATTLIST !ATTLIST defines a list of attributes for an element <!ATTLIST Cherry flavor CDATA #REQUIRED> <!ATTLIST Orange location CDATA #REQUIRED color ‘orange’> !ATTLIST defines a list of attributes for an element Attributes can be of different types, can be required or not required, and they can have default values. Element Attribute Type Flag

DTD –Well-Formed and Valid <?xml version='1.0'?> <!ELEMENT Basket (Cherry+)> <!ELEMENT Cherry EMPTY> <!ATTLIST Cherry flavor CDATA #REQUIRED> -------------------------------------------------------------------------------- Not Well-Formed <basket> <Cherry flavor=good> </Basket> Well-Formed but Invalid <Job> <Location>Home</Location> </Job> Well-Formed and Valid <Basket> <Cherry flavor=‘good’/> </Basket>

XPath – Navigating Xml When Xml is stored in a tree, XPath allows you to navigate to different nodes: Class <Class> <Student>Jeff</Student> <Student>Pat</Student> </Class> Student Student Text: Jeff Text: Pat

XPath – Navigating Xml Xml is similar to a file structure, but you can select more than one node: //Class/Student Class <Class> <Student>Jeff</Student> <Student>Pat</Student> </Class> Student Student Text: Jeff Text: Pat

XPath – Navigating Xml An XPath expression looks just like a file path Elements are accessed as /<element>/ Attributes are accessed as @attribute Everything that satisfies the path is selected You can add constraints in brackets [ ] to further refine your selection

XPath – Navigating Xml Starting Element Attribute Constraint <class name=‘CS 433’> <location building=‘Olin’ room=‘255’/> <professor>Johannes Gehrke</professor> <ta>Dan Kifer </ta> <student_list> <student id=‘999-991’>John Smith</student> <student id=‘999-992’>Jane Doe</student> </student_list> </class> Starting Element Attribute Constraint //class[@name=‘CS 433’]/student_list/student/@id Element Path Selection Selection Result: The attribute nodes containing 999-991 and 999-992

XPath - Context Context – your current focus in an Xml document Use: //<root>/… When you want to start from the beginning of the Xml document

XPath - Context XPath: List/Student Class Prof Location List Text: Gehrke Attr: Olin Student Student Text: Jeff Text: Pat

XPath - Context XPath: Student Student Text: Jeff Pat Prof Gehrke List Location Attr: Olin Class

XPath – Examples Select all of the red apples: <Basket> <Cherry flavor=‘sweet’/> <Cherry flavor=‘bitter’/> <Cherry/> <Apple color=‘red’/> <Apple color=‘green’/> … </Basket> Select all of the red apples: //Basket/Apple[@color=‘red’]

XPath – Examples Select the cherries that have some flavor: <Basket> <Cherry flavor=‘sweet’/> <Cherry flavor=‘bitter’/> <Cherry/> <Apple color=‘red’/> <Apple color=‘green’/> … </Basket> Select the cherries that have some flavor: //Basket/Cherry[@flavor]

XPath – Examples Select all the apples in the orchard: <tree> <apple color=‘red’/> </tree> <basket> <apple color=‘green’/> <orange/> </basket> </orchard> Select all the apples in the orchard: //orchard/descendant()/apple

Xslt – Transforming Xml Amazon.com order form: <single_book_order> <title>Databases</title> <qty>1</qty> </single_book_order> Supplier’s order form: <form7957> <purchase item=’book’ property=’title’ value=’Databases’ quantity=’1’/> </form7957>

Xslt - Extensible Style Language for Transformation Xslt is a language for transforming or converting one Xml format into another Xml format. Benefits: No need to parse or interpret many different Xml formats – they can all be transformed to a single format to facilitate interpretation Language looks like Xml! (remember, Xml defines languages!)

Xslt – A First Look <?xml version='1.0'?> <single_book_order> <title>Databases</title> <qty>1</qty> </single_book_order> <form7957> <purchase item=’book’ property=’title’ value=’Databases’ quantity=’1’/> </form7957> <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:template match='single_book_order'> <form7957><purchase item='book' property='title' value='{title}‘ quantity='{qty}'/></form7957> </xsl:template> </xsl:stylesheet>

Xslt – Header Xslt stylesheets MUST include this body: <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> … </xsl:stylesheet>

Xslt – Templates Xslt stylesheets are a collection of templates Templates are like functions The body of a template is the output of a transformation

Xslt - Templates You define a template with the <xsl:template match=‘’> instruction You call a template with the <xsl:apply-templates select=‘’> instruction 1. All elements or attributes that satisfy the the select attribute expression are selected. 2. For each element or attribute that is selected: i. A matching template is found in the stylesheet. ii. The body of the template is executed.

Xslt – Template Matching Stylesheet <xsl:template match=‘basket’> <new_basket> <xsl:apply-templates select=‘apple’/> <xsl:apply-templates select=‘box’/> </new_basket> </xsl:template> <xsl:template match=‘apple’> <apple/> <xsl:template match=‘box’> <box/> <xsl:apply-templates/> <xsl:template> Xml <basket> <apple color=‘red’/> <apple color=‘green/> <box> <orange taste=‘good’/> <peach/> </box> </basket> Transformed Xml: <apple/> <apple/> <apple/> <box/><apple/>

Xslt – choose Instruction <xsl:choose> instruction is similar to a C++ or Java switch statement <xsl:when test=‘’> instruction is similar to the case statement <xsl:otherwise> instruction is similar to the default statement

Xslt – choose Example Original Xml: <customer> <order id=‘5’> <item><title>Database Management Systems</title></item> </order> </customer> Xslt Stylesheet: <xsl:template match=‘customer’>  FUNCTION <xsl:choose>  SWITCH <xsl:when test='order/@id'>  CASE <single_book_order> <title><xsl:value-of select='order/item/title'/></title> </single_book_order> </xsl:when> <xsl:otherwise><single_book_order><fail/>  DEFAULT </single_book_order></xsl:otherwise> </xsl:choose> </xsl:template> Output Xml: <single_book_order><title>Database Management Systems</title></single_book_order>

Xslt – choose Example 2 Original Xml: <customer> <order> <item><title>Database Management Systems</title></item> </order> </customer> Xslt Stylesheet: <xsl:template match=‘customer’>  FUNCTION <xsl:choose>  SWITCH <xsl:when test='order/@id'>  CASE <single_book_order> <title><xsl:value-of select='order/item/title'/></title> </single_book_order> </xsl:when> <xsl:otherwise><single_book_order><fail/>  DEFAULT </single_book_order></xsl:otherwise> </xsl:choose> </xsl:template> Output Xml: <single_book_order><fail/></single_book_order>

Xslt – for-each Instruction <xsl:for-each select=‘item’> instruction is similar to a foreach iterator or a for loop The select attribute selects a set of elements from an Xml document

Xslt – if Instruction <xsl:if test=‘’> instruction is similar to an if statement in Java or C++ The test attribute is the if condition: True statement is true test returns an element or attribute. False statement is false test returns nothing There is no ‘else’, so use the <xsl:choose> operator in this situation.

Xslt – for-each and if Example Original Xml: <basket> <apple color=‘red’ condition=‘yummy’/> <apple color=‘green’ condition=‘wormy/> <apple color=‘red’ condition=‘crisp’/> </basket> Xslt Stylesheet: <xsl:template match=‘basket’>  FUNCTION <condition_report> <xsl:for-each select=‘apple’>  FOR LOOP <xsl:if test=“contains(@color, ‘red’)”>  IF <condition><xsl:value-of select=‘@condition’/></condition> </xsl:if> </xsl:for-each> </condition_report> </xsl:template> Output Xml: <condition_report> <condition>yummy</condition> <condition>crisp</condition>

Xslt – Other Information W3C is standardizing XPath and Xslt: http://www.w3.org/TR/xslt.html http://www.w3.org/TR/xpath.html Lot’s of Books. Here’s a suggestion: D. Martin et al. Professional Xml. Wrox Press, 2000.

What’s Next? XSchema XQuery DTDs, but written in XML Will replace DTDs Fully declarative XML query language Will be able to do anything you can do with XPath and XSLT, plus a LOT more

Xml in Commercial Databases Many Xml parsers and XSLT engines are availbable Microsoft, IBM, and Oracle (among others) are adding native Xml support Native Xml databases

URL Tutorials http://msdn.microsoft.com/xml/tutorial/default.asp http://www.ils.unc.edu/~kempa/inls259/xml/ http://www.geocities.com/SiliconValley/Peaks/5957/10minxml.html