Xml, DTD, XPath, & Xslt

  • View

  • Download

Embed Size (px)


Xml, DTD, XPath, & Xslt. Extensible Markup and Beyond. Overview. Xml A self-describing, hierarchal data model DTD 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. - PowerPoint PPT Presentation

Text of Xml, DTD, XPath, & Xslt

  • Xml, DTD, XPath, & XsltExtensible Markup and Beyond

  • OverviewXmlA self-describing, hierarchal data modelDTDStandardizing schemas for XmlXPathHow to navigate and query Xml documentsXsltHow to transform one Xml document into another Xml document

  • Xml An Example

    Johannes GehrkeDan Kifer John SmithJane Doe

  • Xml Extensible Markup Language LanguageA way of communicating information MarkupNotes or meta-data that describe your data or language ExtensibleLimitless ability to define new languages or data sets

  • Xml Whats The Point?You can include your data and a description of what the data representsThis is useful for defining your own language or protocol Example: Chemical Markup Language234.5

  • Xml StructureXml looks like HTMLXml is a hierarchy of user-defined tags called elements with attributes and dataData is described by elements, elements are described by attributes

    John Smith

  • Xml ElementsJohn Smith

    Xml is case and space sensitiveElement opening and closing tag names must be identicalOpening tags: Closing tags: Empty Elements have no data and no closing tag: They begin with a

  • Xml AttributesJohn Smith

    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_valueThere 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).

  • Xml - DataJohn Smith

    Xml data is any information between an opening and closing tagXml data must not contain the characters

  • Xml Nesting & HierarchyXml tags can be nested in a tree hierarchyXml documents can have only one root tagBetween an opening and closing tag you can insert:1. Data2. More Elements3. A combination of data and elements

    Some Text More

  • Xml Storage Storage is done just like an n-ary tree (DOM)

    Some Text More

  • Xml vs. Relational ModelComputer Table

    800Mhz 256MB 40GB 933Mhz 512MB 40GB


  • DTD Document Type DefinitionA DTD is a schema for Xml dataXml protocols and languages can be standardized with DTD filesA DTD says what elements and attributes are required or optionalDefines the formal structure of the language

  • DTD An Example



    !ELEMENT declares an element name, and what children elements it should have Wildcards:* Zero or more+ One of moreNameChildren


    !ATTLIST defines a list of attributes for an elementAttributes can be of different types, can be required or not required, and they can have default values.ElementAttributeTypeFlag

  • DTD Well-Formed and Valid


    Well-Formed and Valid

    Not Well-Formed

    Well-Formed but Invalid


  • XPath Navigating XmlWhen Xml is stored in a tree, XPath allows you to navigate to different nodes:ClassStudentStudentText:JeffText:Pat

    Jeff Pat

  • XPath Navigating XmlXml is similar to a file structure, but you can select more than one node://Class/StudentClassStudentStudentText:JeffText:Pat

    Jeff Pat

  • XPath Navigating Xml An XPath expression looks just like a file pathElements are accessed as //Attributes are accessed as @attribute Everything that satisfies the path is selectedYou can add constraints in brackets [ ] to further refine your selection

  • XPath Navigating Xml

    Johannes Gehrke Dan Kifer John Smith Jane Doe

    //class[@name=CS 433]/student_list/student/@idStarting ElementAttribute ConstraintElement PathSelectionSelection Result: The attribute nodes containing 999-991 and 999-992

  • XPath - ContextContext your current focus in an Xml document Use:/// When you want to start from the beginning of the Xml document

  • XPath - ContextStudentStudentText:JeffText:PatProfText:GehrkeListLocationAttr:OlinClassXPath: List/Student

  • XPath - ContextXPath: Student

  • XPath Examples

    Select all of the red apples:


  • XPath Examples

    Select the cherries that have some flavor:


  • XPath Examples

    Select all the apples in the orchard://orchard/descendant()/apple

  • Xslt Transforming XmlAmazon.com order form:

    Databases 1

    Suppliers order form:

  • 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 interpretationLanguage looks like Xml! (remember, Xml defines languages!)

  • Xslt A First Look

    Databases 1

  • Xslt HeaderXslt stylesheets MUST include this body:

  • Xslt TemplatesXslt stylesheets are a collection of templatesTemplates are like functionsThe body of a template is the output of a transformation

  • Xslt - TemplatesYou define a template with the instructionYou call a template with the instruction1. 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



    Transformed Xml:

  • Xslt choose Instruction instruction is similar to a C++ or Java switch statement instruction is similar to the case statement instruction is similar to the default statement

  • Xslt choose Example Original Xml: Database Management Systems


    Output Xml:Database Management Systems

  • Xslt choose Example 2 Original Xml: Database Management Systems


    Output Xml:

  • Xslt for-each Instruction instruction is similar to a foreach iterator or a for loopThe select attribute selects a set of elements from an Xml document

  • Xslt if Instruction instruction is similar to an if statement in Java or C++The test attribute is the if condition:Truestatement is truetest returns an element or attribute.False statement is falsetest returns nothingThere is no else, so use the operator in this situation.

  • Xslt for-each and if Example Original Xml:

    Xslt Stylesheet: FUNCTION FOR LOOP IF

    Output Xml: yummy crisp

  • Xslt Other Information W3C is standardizing XPath and Xslt:



    Lots of Books. Heres a suggestion: D. Martin et al. Professional Xml. Wrox Press, 2000.

  • URL Tutorialshttp://msdn.microsoft.com/xml/tutorial/default.asp