Click here to load reader

XML, DTD, XML Schema, and XSLT

  • View

  • Download

Embed Size (px)


XML, DTD, XML Schema, and XSLT. Jianguo Lu University of Windsor. Where we are. XML DTD XML Schema XML Namespace XPath DOM Tree XSLT. Name Conflict. Apples Bananas . - PowerPoint PPT Presentation

Text of XML, DTD, XML Schema, and XSLT

  • XML, DTD, XML Schema, and XSLT Jianguo LuUniversity of Windsor

  • Where we areXML DTDXML SchemaXML NamespaceXPathDOM TreeXSLT

  • Name ConflictSolution: add prefix to the tag names Apples Bananas African Coffee Table 80 120 Apples Bananas African Coffee Table 80 120

  • Name spacestabletrhtmlbodythtdtablepricenamelengthwidthHTML name spaceFurniture name spaceheight

  • XML namespaceAn XML document may use more than one schema;Since each structuring document was developed independently, name clashes may appear;The solution is to use a different prefix for each schema prefix:name

    557 10

  • Namespace namesNamespace names are URIsMany namespace names are in the form of HTTP URI. The purpose of a name space is not to point to a location where a resource resides. It is intended to provide a unique name that can be associated with a particular organization. The URI MAY point to a schema.

    557 10

  • Namespace declarationA namespace is declared using an attribute starts with xmlns.You can declare multiple namespaces in one instance.

    123ABC123 557 10

  • Default namespace declarationDefault namespace maps unprefixed element type name to a namespace.

    123ABC123 557 10

  • Scope of namespace declarationNamespace declaration can appear in any start tag.The scope is in the element where it is declared. 123ABC123 557 10

  • The elements anddatatypes thatare used to constructschemas - schema - element - complexType - sequence - stringcome from the http:///XMLSchemanamespaceFrom CostelloIndicates that theelements definedby this schema - BookStore - Book - Title - Author - Date - ISBN - Publisherare to go in thehttp://www.books.orgnamespace

  • This is referencing a Book element declaration.The Book in whatnamespace? Since thereis no namespace qualifierit is referencing the Bookelement in the defaultnamespace, which is thetargetNamespace! Thus,this is a reference to theBook element declarationin this schema.The default namespace ishttp://www.books.orgwhich is the targetNamespace!From Costello

  • Import in XML SchemaNow with the understanding of namespace, we can introduce some more advanced features in XML Schema.The import element allows you to access elements and types in a different namespace.


  • ExampleCamera.xsdNikon.xsdOlympus.xsdPentax.xsdFrom Costello

  • Nikon.xsd


    Pentax.xsdFrom Costello

  • IncludeThe include element allows you to access components in other schemasAll the schemas you include must have the same namespace as your schema (i.e., the schema that is doing the include)The net effect of include is as though you had typed all the definitions directly into the containing schema

    LibraryBook.xsdLibraryEmployee.xsdLibrary.xsdFrom Costello

  • Library.xsdThese arereferencingelementdeclarationsin otherschemas.From Costello

  • XML PathXML DTDXML SchemaXML NamespaceXPathDOM TreeXSLT

  • XPathLanguage for addressing parts of an XML document. It operates on the tree data model of XMLXPath is a syntax for defining parts of an XML document XPath uses paths to define XML elements It has a non-XML syntax XPath defines a library of standard functions Such as arithmetic expressions.XPath is a major element in XSLT and XML query languagesXPath is a W3C Standard

  • What is XPathLike traditional file pathsXPath uses path expressions to identify nodes in an XML document. These path expressions look very much like the expressions you see when you work with a computer file system:public_html/569/xml.ppt Books/book/author/name/FirstNameAbsolute path/library/author/bookRelative pathauthor/book

  • XML path example

    /library/library/author//author/library/@location//book[@title=Artificial Intelligence]

  • XML Path ExampleAddress all author elements/library/authorAddresses all author elements that are children of the library element node, which resides immediately below the root/t1/.../tn, where each ti+1 is a child node of ti, is a path through the tree representationAddress all author elements//authorHere // says that we should consider all elements in the document and check whether they are of type authorThis path expression addresses all author elements anywhere in the document

  • XPath exampleSelect the location attribute nodes within library element nodes /library/@locationThe symbol @ is used to denote attribute nodes Select all title attribute nodes within book elements anywhere in the document, which have the value Artificial Intelligence //book/@title="Artificial IntelligenceSelect all books with title Artificial Intelligence/library/author/book[@title="Artificial Intelligence"] Test within square brackets: a filter expression It restricts the set of addressed nodes.Difference with previous query. This query addresses book elements, the title of which satisfies a certain condition.Previous query collects title attribute nodes of book elements

  • XPath syntaxA path expression consists of a series of steps, separated by slashes A step consists of An axis specifier, A node test, and An optional predicate

    An axis specifier determines the tree relationship between the nodes to be addressed and the context nodeE.g. parent, ancestor, child (the default), sibling, attribute node// is such an axis specifier: descendant or selfchild::book select all book elements that are children of current node A node test specifies which nodes to address The most common node tests are element names /library/authorE.g., * addresses all element nodes/library/*comment() selects all comment nodes /library/commnets()

  • XPath syntaxPredicates (or filter expressions) are optional and are used to refine the set of addressed nodesE.g., the expression [1] selects the first node[position()=last()] selects the last node[position() mod 2 =0] selects the even nodesXPath has a more complicated full syntax. We have only presented the abbreviated syntax

  • More examplesAddress the first author element node in the XML document//author[1]Address the last book element within the first author element node in the document//author[1]/book[last()]Address all book element nodes without a title attribute//book[not @title]

  • Where we areXML DTDXML SchemaXML NamespaceXPathDOM TreeXSLT

  • How to process XMLXML does not DO anythingProcess XML using general purpose languagesJava, Perl, C++ DOM is the basisProcess XML using special purpose languagestranslate the stock XML file to an HTML table. Transform the XML: XSLTtell me the stocks that are higher that 100.Query XML: XQuery

  • DOM (Document Object Model)What: DOM is application programming interface (API) for processing XML documents unique interface. Platform and language independence.How: It defines the logical structure of documents and the way to access and manipulate itWith the Document Object Model, one canCreate an object treeNavigate its structureAccess, add, modify, or delete elements etc

  • XML tree hierarchyXML can be described by a tree hierarchyDocumentUnitSub-unitDocumentUnitSub-unitParentChildSibling

  • DOM tree modelGeneric tree modelNodeType, name, valueAttributesParent nodePrevious, next sibling nodesFirst, last child nodesMany other entities extends nodeDocumentElementAttribute... ...

  • DOM class hierarchyDocumentFragmentDocumentCharacterDataTextCommentCDATASectionAttrElementDocumentTypeNotationEntityEntityReferenceProcessingInstructionNodeNodeListNamedNodeMapDocumentType

  • JavaDoc of DOM API

  • Remarks on javadocjavadoc is a command included in JDK;It is a useful tool generate HTML description for your programs, so that you can use a browser to look at the description of the classes;JavaDoc describes classes, their relationships, methods, attributes, and comments.When you write java programs, the JavaDoc is the first place that you should look at:For core java, there is JavaDoc to describe every class in the language; To know how to use DOM, look at the javaDoc of org.w3c.dom package.If you are a serious java programmer: you should have the core jdk javaDoc ready on your hard disk;You should generate the javaDoc for other people to look at. To run javadoc, type D>javadoc *.javaThis is to generate JavaDoc for all the classes under current directory.

  • Methods in Node interfaceThree categories of methodsNode characteristicsname, type, valueContextual location and access to relativesparents, siblings, children, ancestors, descendantsNode modificationEdit, delete, re-arrange child nodes

  • XML parser and DOMWhen you parse an XML document with a DOM parser, you get back a tree structure that contains all of the elements of your document;DOM also provides a variety of functions you can use to examine the contents and structure of the document.DOM APIDOMXML parserDOM TreeYour XML application

  • DOM tree and DOM classes


    Amazon incamzn15.45Elementchild

  • Use Java to process XMLTasks:How to construct the DOM tree from an XML text file?How to get the list of stock elements?How to get the attribute value of the second stock element?Construct the Document object:Need to use an XML parser (XML4J);Remember to import the necessary packages;The benefits of DOM: the following lines are the only difference if you use another DOM XML parser.

  • Get the first stock element

    amazon corp amzn 16 IBM in

Search related