0% found this document useful (0 votes)
7 views

XML notes

XML, or eXtensible Markup Language, is a markup language designed for storing and transporting data in a self-descriptive manner. It includes a structured document format with a root element, proper tag closure, and case sensitivity, and can be validated using Document Type Definitions (DTD) or XML Schemas. XML namespaces help avoid naming conflicts, and styles can be applied using CSS linked to XML files.

Uploaded by

shreyassupe346
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)
7 views

XML notes

XML, or eXtensible Markup Language, is a markup language designed for storing and transporting data in a self-descriptive manner. It includes a structured document format with a root element, proper tag closure, and case sensitivity, and can be validated using Document Type Definitions (DTD) or XML Schemas. XML namespaces help avoid naming conflicts, and styles can be applied using CSS linked to XML files.

Uploaded by

shreyassupe346
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/ 19

XML

EXTENSIBLE MARKUP LANGUAGE


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 document structure
• XML declaration
• Must have one root element
• Every tag is opened and ended properly
• Attributes are inside the quotes.
• It is case sensitive.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Document Type Definition (DTD)
• A Document Type Definition (DTD) describes the tree structure of a document
and something about its data.

• There are 2 data types, PCDATA and CDATA


• PCDATA is parsed character data.
• CDATA is character data, not usually parsed.
• <!DOCTYPE element DTD identifier

•[

• first declaration

• second declaration . .
Document Type Definition (DTD)
• <?xml version="1.0"?> • <address>
• <!DOCTYPE address [ • <name>
• <!ELEMENT address (name, email, phone, • <first>Rohit</first>
birthday)>
• <last>Sharma</last>
• <!ELEMENT name (first, last)>
• </name>
• <!ELEMENT first (#PCDATA)>
• <email>sharmarohit@gmail.com</email>
• <!ELEMENT last (#PCDATA)>
• <phone>9876543210</phone>
• <!ELEMENT email (#PCDATA)>
• <birthday>
• <!ELEMENT phone (#PCDATA)>
• <year>1987</year>
• <!ELEMENT birthday (year, month, day)>
• <month>June</month>
• <!ELEMENT year (#PCDATA)>
• <day>23</day>
• <!ELEMENT month (#PCDATA)>
• </birthday>
• <!ELEMENT day (#PCDATA)>
• </address>
• ]>
• The DTD above is interpreted like this: • !ELEMENT email defines the email element to
be of type “#PCDATA”.
• !DOCTYPE address defines that the root
element of this document is address. • !ELEMENT phone defines the phone element
to be of type “#PCDATA”.
• !ELEMENT address defines that the address
element must contain four elements: “name, • !ELEMENT birthday defines that the birthday
email, phone, birthday”. element must contain three elements “year,
month, day”.
• !ELEMENT name defines that the name
element must contain two elements: “first, • !ELEMENT year defines the year element to be of
type “#PCDATA”.
last”.
• !ELEMENT month defines the month element to be of
• !ELEMENT first defines the first element to be of type “#PCDATA”.
type “#PCDATA”.
• !ELEMENT day defines the day element to be of type
• !ELEMENT last defines the last element to be of “#PCDATA”.
type “#PCDATA”.

Example
Example
XML Namespaces
• XML Namespace is used to avoid element name conflict in XML
document.
• XML Namespace Declaration
• An XML namespace is declared using the reserved XML attribute.
This attribute name must be started with "xmlns".
• <element xmlns:name = "URL">
• Here, namespace starts with keyword "xmlns". The word name is a
namespace prefix.
• The URL is a namespace identifier. A Uniform Resource Identifier
(URI) is a string of characters which identifies an Internet Resource.
Let's take an example with two tables:

• This XML carries information about an HTML table, and a piece of furniture:
If these XML fragments were added together, there would be a
<table> name conflict. Both contain a <table> element, but the elements
have different content and meaning.
<tr>
<td>Apples</td>
<table>
<td>Bananas</td>
<name>African Coffee
</tr>
Table</name>
</table>
<width>80</width>
<length>120</length>
</table>
Let's take an example with two tables:

• This XML carries information about an HTML table, and a piece of furniture:
Solving the Name Conflict Using a Prefix

<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
The xmlns Attribute
• 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.
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
XML Schema
•An XML Schema describes the structure of an XML
document, just like a DTD.

•An XML document with correct syntax is called "Well


Formed".

•An XML document validated against an XML Schema is both


"Well Formed" and "Valid".

•It is like DTD but provides more control on XML structure.


•XML Schema Data types
•There are two types of data types in XML schema.
•simple Type
•complexType
•simpleType
•The simpleType allows you to have text-based elements. It contains
less attributes, child elements, and cannot be left empty.
•complexType
•The complexType allows you to hold multiple attributes and
elements. It can contain additional sub elements and can be left
empty.
Example
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
• XML Schemas use XML Syntax
• Another great strength about XML Schemas is that they are written in XML:
• You don't have to learn a new language
• You can use your XML editor to edit your Schema files
• You can use your XML parser to parse your Schema files
• You can manipulate your Schemas with the XML DOM
Title and Content Layout with List
• Add your first bullet point here
• Add your second bullet point here
• Add your third bullet point here
How to link XML file with CSS
•To link XML files with CSS, you should use the following syntax:
•<?xml-stylesheet type="text/css" href="cssemployee.css"?>
employee <?xml version="1.0"?>
{ <?xml-stylesheet type="text/css"
background-color: pink; href="cssemployee.css"?>
} <!DOCTYPE employee SYSTEM
firstname,lastname,email "employee.dtd">
{ <employee>
font-size:25px; <firstname>vimal</firstname>
display:block; <lastname>jaiswal</lastname>
color: blue; <email>vimal@gmail.com</email>
margin-left: 50px; </employee>
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy