Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views12 pages

Lecture 26

Uploaded by

kmani11811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views12 pages

Lecture 26

Uploaded by

kmani11811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Web Technologies

eXtensible Markup Language (XML)


Today’s Lecture
XML
• XML Introduction
• XML Tree
• XML Syntax
• XML Elements
• XML Parser
• XML DOM
• XML Schema
XML
• XML stands for eXtensible Markup Language.
• XML was designed to store and transport/distribute data.
• XML became a W3C Recommendation in February 1998.
• XML was designed to be self-descriptive.
• XML has user defined tags, not predefined tags.
– With XML, author must define tags and document structure.
– Whereas HTML works with predefined tags like <p>, <h1>,
<table>, etc.
XML Tree
• XML documents are formed as element trees.
• XML tree starts at a root element (parent) and branches from root
to child elements.
• All elements can have sub elements (child elements):
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
– Parent, child, and sibling are used to describe relationships
between elements.
• Parents have children.
• Children have parents.
XML Tree
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

In above code, <?xml version="1.0" encoding="UTF-8"?> (XML Prolog) defines XML version and
character encoding.
XML Syntax
• Syntax rules of XML are very simple and logical:
– XML Documents must have a root element (parent).
– All XML elements must have a closing tag.
– XML tags are case sensitive.
– XML elements must be properly nested.
– XML attribute values must always be quoted.
XML Elements
• XML document contains XML Elements.
• XML element is everything from element's start tag to element's end tag.
• Element can contain text, attributes, or other elements.
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J. K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
XML Parser
• XML DOM defines properties and methods for accessing and editing XML.
– However, before an XML document can be accessed, it must be loaded
into an XML DOM object.
– All modern browsers have a built-in XML parser that can convert text
into an XML DOM object.
• Example: parses a text string into an XML DOM object, and extracts info
from it with JavaScript.
<html><body><p id="demo"></p>
<script>
var text, parser, xmlDoc;
text = "<bookstore><book>" + "<title>Everyday Italian</title>" + "<author>Giada De
Laurentiis</author>" + "<year>2005</year>" + "</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
</body></html>
Everyday Italian
XML DOM
• DOM
– It defines a standard for accessing and manipulating documents.
• HTML DOM
– It defines a standard way for accessing and manipulating HTML
documents.
• It presents an HTML document as a tree-structure.
• XML DOM
– It defines a standard way for accessing and manipulating XML
documents.
• It presents an XML document as a tree-structure.
XML Schema
• XML Schema describes the structure of an XML document.
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
– <xs:element name="note"> defines element called "note".
– <xs:complexType> "note" element is a complex type.
– <xs:sequence> complex type is a sequence of elements.
– <xs:element name="to" type="xs:string"/> element "to" is of type string.
– <xs:element name="from" type="xs:string"/> element "from" is of type string.
– <xs:element name="heading" type="xs:string"/> element "heading" is of type string.
– <xs:element name="body" type="xs:string"/> element "body" is of type string.
Summary of Today’s Lecture
XML
• XML Introduction
• XML Tree
• XML Syntax
• XML Elements
• XML Parser
• XML DOM
• XML Schema
References
• https://www.w3.org/XML/
• https://www.w3schools.com/xml/xml_whatis.asp

You might also like