XML What Is XML?
XML What Is XML?
What is XML?
• XML stands for eXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• XML is a W3C Recommendation
The World Wide Web Consortium (W3C) develops standards and guidelines to help
everyone build a web based on the principles of accessibility, internationalization, privacy
and security.
• With XML, the author must define both the tags and the document structure.
• XML AJAX
• XML DOM
• XML XPath
• XML XSLT : can be used to transform XML into other language
• XML XQuery
• XML DTD
• XML Schema
• XML Service
https://www.w3schools.com/xml/default.asp
XML documents form a tree structure that starts at "the root" and branches to "the
leaves".
This is known as prolog: A prolog defines the XML version and the character encoding: its not necessary. It does not
have closing tag. This is not considered part of xml document.
Rules:
• All elements has a root element, that is parent of all the elements
• There is an otional prolog, that is first line in xml doc.
• Case sensitive
• Elements shall be properly nested
• Attribute values must be quoted.
• Element names cant start with xml, Xml, XML, etc. Element names can contain
letters, digits, hyphens, underscores, and periods
XML Namespaces
(ispe madam ne number nhi die the)
<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="https://www.w3schools.com/furniture">
XML HttpRequest
All modern browsers have a built-in XMLHttpRequest object to request data from a
server. No need to reload the page to do so.
<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>";
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
What is the DOM?
The Document Object Model (DOM) defines a standard for accessing and manipulating
documents:
The XML DOM is a standard for how to get, change, add, and delete XML elements.
What is XPath?
XPath is a major element in the XSLT standard.
-
XSLT
• With XSLT you can transform an XML document into HTML.
• With XSLT you can add/remove elements and attributes to or from the output file.
• You can also rearrange and sort elements, perform tests and make decisions about
which elements to hide and display, and a lot more.
There are two different document type definitions that can be used with XML:
What is a DTD?
DTD stands for Document Type Definition.
A DTD defines the structure and the legal elements and attributes of an XML document.
With a DTD, independent groups of people can agree to use a standard DTD for
interchanging data.
With a DTD, you can verify that the data you receive from the outside world is valid.
Example:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
XML Schema
An XML Schema describes the structure of an XML document, just like a DTD.
An XML document validated against an XML Schema is both "Well Formed" and
"Valid".
<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>