XML Anisha K J Jerrin Thomas. Outline Introduction Structure of an XML Page Well-formed & Valid...

31
XML XML Anisha K J Jerrin Thomas

Transcript of XML Anisha K J Jerrin Thomas. Outline Introduction Structure of an XML Page Well-formed & Valid...

Page 1: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

XML XML

Anisha K J

Jerrin Thomas

Page 2: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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

Page 3: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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.

Page 4: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Why do we need Xml

Data-exchange Makes communication easy. Possible to define other languages.

Page 5: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Structure of an XML Page

<?xml version="1.0"?><!DOCTYPE root system “address”> <Root> <Element> <Sub-element>Content</Sub-element><Element></Root>

Page 6: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Logical Structure

The Prolog 1. XML declaration

2. Document type declaration

The Document Element

Page 7: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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

Page 8: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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:<tag/>

Page 9: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Elements and Sub-elements

Example:

<car>

<brand>volvo</brand>

<type>v40</type>

<color>green</color>

</car>

Page 10: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Attributes Syntax: <Element attribute-name = "attribute-value">....</Element> Example: <Car color = "green">volvo</car> The same information can also be defined without using

attributes as follows:<Car><Brand>volvo</brand><Color>green</color></Car>

Page 11: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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.

Page 12: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Valid Xml Documents

The document must be well formed. The document must follow the rules defined in

DTD.

Page 13: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

DTD – Document Type Definition

Contains rules for particular type of Xml documents.

It describes the set of valid:1. Elements

2. Attributes

3. Entities

Page 14: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Elements

XML elements are declared with an element declaration. The syntax is:

<!ELEMENT element-name category> <!ELEMENT element-name (element-content)> Category: #PCDATA, EMPTY, ANY Element content: Data or Sub-elements

Page 15: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Number of Sub-elements

+ one or more * zero or more ? Once or not at all | Choice

Page 16: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Attributes

Syntax: <!ATTLIST element-name attribute-name attribute-type default-value>

E.g.: <!ATTLIST payment type CDATA "check">

Page 17: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Attribute type

1. CDATA The value is character data

2. (en1|en2|..) The value must be one from an enumerated list

3. ID The value is a unique id

4. IDREF The value is the id of another element

5. IDREFS The value is a list of other ids

6. NMTOKEN The value is a valid XML name

7. NMTOKENS The value is a list of valid XML names

8. ENTITY The value is an entity

9. ENTITIES The value is a list of entities

10. NOTATION The value is a name of a notation

11. xml: The value is a predefined xml value

Page 18: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Default values

1. Value The default value of the attribute

2. #REQUIRED The attribute value must be included

3. #IMPLIED The attribute need not be included

4. #FIXED value The attribute value is fixed

Page 19: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Entities

Internal Entity Declaration External Entity Declaration Syntax:

<!ENTITY entity-name "entity-value"> DTD Example:

<!ENTITY writer "Donald Duck.">

<!ENTITY copyright "Copyright W3Schools."> XML example: <author>&writer;&copyright;</author>

Page 20: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Internal & External DTDs

Internal: <!DOCTYPE name of rootelement[element definitions]>

External:<!DOCTYPE name of root element SYSTEM “address”>

DTD is specified after Xml declaration

Public DTD: Used for broad and public usage

Page 21: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

XML Parsing Strategies

Simple API for Xml(SAX) Document Object Model(DOM) Xml pull parsing

Page 22: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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.

Page 23: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Node Types

1. Document type: <!DOCTYPE food SYSTEM "food.dtd">

2. Processing inst: <?xml version="1.0"?>

3. Element: <drink type="beer">Carlsberg</drink>

4. Attribute: type="beer"

5. Text: Carlsberg

Page 24: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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

Page 25: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

XML Technologies

XSL – XSLT, XSL-FO, Xpath XQuery XML Schema XForms

Page 26: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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

Page 27: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

XQuery

XQuery is a language for querying XML data XQuery is built on XPath expressions XQuery for XML is like SQL for databases

Page 28: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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

Page 29: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

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)

Page 30: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Conclusion

XML page with our own tags, attributes etc. DTD – Document Type Definition. Parsing – DOM, SAX >> to application layer. Display – CSS, XSL.

Page 31: XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.

Thank YouThank You