Outline Introduction Structure of an XML Page Well-formed & Valid XML Documents DTD – Elements, Attributes, Entities Parsing Strategies – DOM, SAX XML Technologies – XSL, XQuery, Etc
Introduction Extensible Markup Language. Used to describe data. Can define our own tags. Define data structures. Make these Structures platform independent. Process Xml defined data automatically.
Why do we need Xml Data-exchange Makes communication easy. Possible to define other languages.
Logical Structure The Prolog 1. XML declaration 2. Document type declaration The Document Element
Physical Structure The content of an XML file is contained in chunks of information called entities. 1. Internal or External 2. Parsed or Unparsed Attributes
Tags Should have start tag and closing tag Tags are case sensitive All tags must be nested properly Comments can be used as in HTML<!— comments Between start and empty tag there is content Empty Tag:
Elements and Sub-elements Example: volvo v40 green
Attributes Syntax:.... Example: volvo The same information can also be defined without using attributes as follows: volvo green
Well Formed Xml Documents Contain a root element. All other elements are children of the root element. All elements are correctly paired. The element name in a start-tag and an end-tag are exactly the same. Attribute names are used only once within the same element.
Valid Xml Documents The document must be well formed. The document must follow the rules defined in DTD.
DTD – Document Type Definition Contains rules for particular type of Xml documents. It describes the set of valid: 1. Elements 2. Attributes 3. Entities
Elements XML elements are declared with an element declaration. The syntax is: Category: #PCDATA, EMPTY, ANY Element content: Data or Sub-elements
Number of Sub-elements + one or more * zero or more ? Once or not at all | Choice
Attribute type 1.CDATAThe value is character data 2.(en1|en2|..) The value must be one from an enumerated list 3.IDThe value is a unique id 4.IDREFThe value is the id of another element 5.IDREFSThe value is a list of other ids 6.NMTOKENThe value is a valid XML name 7.NMTOKENSThe value is a list of valid XML names 8.ENTITYThe value is an entity 9.ENTITIESThe value is a list of entities 10.NOTATIONThe value is a name of a notation 11.xml:The value is a predefined xml value
Default values 1.ValueThe default value of the attribute 2.#REQUIREDThe attribute value must be included 3.#IMPLIEDThe attribute need not be included 4.#FIXED valueThe attribute value is fixed
Internal & External DTDs Internal: External: DTD is specified after Xml declaration Public DTD: Used for broad and public usage
XML Parsing Strategies Simple API for Xml(SAX) Document Object Model(DOM) Xml pull parsing
DOM – Document Object Model The DOM represents a tree view of the XML document. A node interface model is used to access the individual elements in the node tree. XML elements can be extracted from an XML document by traversing the node tree, by accessing the elements by number, or by accessing the elements by name.
XML DOM Objects 1.DOM Node 2.DOM NodeList 3.DOM Document 4.DOM Element 5.DOM Attr 6.DOM Text 7.DOM CDATA 8.DOM Comment
XML Technologies XSL – XSLT, XSL-FO, Xpath XQuery XML Schema XForms
XSL - eXtensible Stylesheet Language XSL consists of three parts: XSLT is a language for transforming XML documents XPath is a language for defining parts of an XML document XSL-FO is a language for formatting XML documents
XQuery XQuery is a language for querying XML data XQuery is built on XPath expressions XQuery for XML is like SQL for databases
XML Schema The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. Soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: 1. XML Schemas are extensible to future additions 2. XML Schemas are richer and more useful than DTDs 3. XML Schemas are written in XML 4. XML Schemas support data types 5. XML Schemas support namespaces
XForms XForms are the next generation of HTML forms XForms are designed to handle interactive transactions XForms are platform and device independent XForms separate data and logic from presentation XForms use XML to define forms XForms contain features like calculations and validations of forms (less scripting is required)
Conclusion XML page with our own tags, attributes etc. DTD – Document Type Definition. Parsing – DOM, SAX >> to application layer. Display – CSS, XSL.