XML Anisha K J Jerrin Thomas. Outline Introduction Structure of an XML Page Well-formed & Valid...
Transcript of XML Anisha K J Jerrin Thomas. Outline Introduction Structure of an XML Page Well-formed & Valid...
XML XML
Anisha K J
Jerrin Thomas
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.
Structure of an XML Page
<?xml version="1.0"?><!DOCTYPE root system “address”> <Root> <Element> <Sub-element>Content</Sub-element><Element></Root>
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:<tag/>
Elements and Sub-elements
Example:
<car>
<brand>volvo</brand>
<type>v40</type>
<color>green</color>
</car>
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>
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:
<!ELEMENT element-name category> <!ELEMENT element-name (element-content)> 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
Attributes
Syntax: <!ATTLIST element-name attribute-name attribute-type default-value>
E.g.: <!ATTLIST payment type CDATA "check">
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
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
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;©right;</author>
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
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.
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
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.
Thank YouThank You