0% found this document useful (0 votes)
25 views15 pages

XML What Is XML?

Uploaded by

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

XML What Is XML?

Uploaded by

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

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

• Maybe it is a little hard to understand, but XML does not DO anything.

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.

The Difference Between XML and HTML


XML and HTML were designed with different goals:

• XML was designed to carry data - with focus on what data is


• HTML was designed to display data - with focus on how data looks
• XML tags are not predefined like HTML tags are

• 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.

<?xml version="1.0" encoding="UTF-8"?>

Well Formed XML


XML documents that conform to the syntax rules below are said to be "Well Formed" XML
documents.

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

Meow meow things:


• Comment is <!— ye ra comment -->
• Whitespace is preserved:…………this has more space…………… will be
represented as such in xml.
• Xml stores new line as LF
metadata (data about data) should be stored as attributes, and the data itself should be
stored as elements.

XML Namespaces
(ispe madam ne number nhi die the)

XML Namespaces provide a method to avoid element name conflicts.

Name conflicts in XML can easily be avoided using a name prefix.


When using prefixes in XML, a namespace for the prefix must be defined.
The namespace can be defined by an xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".

Namespaces can also be declared in the XML root element:

<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.

The XMLHttpRequest.readyState property returns the state an XMLHttpRequest client is


in.

The XMLHttpRequest Object has a built in XML Parser.

The responseText property returns the response as a string.

The responseXML property returns the response as an XML DOM object.


XML Parser
All modern browsers have a built-in XML parser that can convert text into an XML DOM
object.

<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>
What is the DOM?
The Document Object Model (DOM) defines a standard for accessing and manipulating
documents:

It presents an XML document as a tree-structure.

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.

XPath can be used to navigate through elements and


attributes in an XML document.

• XPath is a syntax for defining parts of an XML document


• XPath uses path expressions to navigate in XML documents
• XPath contains a library of standard functions

XPath uses path expressions to select nodes or node-sets in an XML document

-
XSLT
• With XSLT you can transform an XML document into HTML.

• XSLT (eXtensible Stylesheet Language Transformations) is the recommended style


sheet language for XML.

• XSLT is far more sophisticated than CSS.

• 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.

• XSLT uses XPath to find information in an XML document.


XLink and XPointer
Valid XML Documents
A "valid" XML document must be well formed. In addition, it must conform to a document
type definition.

There are two different document type definitions that can be used with XML:

• DTD - The original Document Type Definition


• XML Schema - An XML-based alternative to DTD

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".

• XML Schemas are written in XML


• XML Schemas are extensible to additions
• XML Schemas support data types
• XML Schemas support namespaces

<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>

Referencing the schema:

You might also like