[go: up one dir, main page]

0% found this document useful (0 votes)
186 views23 pages

SGML and XML

The document discusses XML (eXtensible Markup Language), its benefits and uses, as well as how to define the structure of XML documents using XML Schema (XSD). Some key points covered include: - XML allows users to define their own tags, is extensible, self-descriptive, and scalable. It facilitates information interchange on the web. - XML Schema (XSD) defines the structure and elements of an XML document, similar to a DTD but with more control over structure. An XML document is validated against a schema to check it follows the defined rules. - An XML schema example provided defines an "employee" element with child elements for first name, last name,

Uploaded by

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

SGML and XML

The document discusses XML (eXtensible Markup Language), its benefits and uses, as well as how to define the structure of XML documents using XML Schema (XSD). Some key points covered include: - XML allows users to define their own tags, is extensible, self-descriptive, and scalable. It facilitates information interchange on the web. - XML Schema (XSD) defines the structure and elements of an XML document, similar to a DTD but with more control over structure. An XML document is validated against a schema to check it follows the defined rules. - An XML schema example provided defines an "employee" element with child elements for first name, last name,

Uploaded by

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

SGML is a vast and powerful generalized markup language that is used to define

descriptions for the structure of several electronic documents.

XML stands for eXtensible Markup Language. It is a simple and flexible markup language. It
is known as universal language for data on the web because XML documents can be created
and used in any language. It is universal standard for information interchange.

XML technology facilitates you to create your own markup language.

These are the main benefits of using XML.

Simplicity: Very easy to read and understand the information coded in XML.

Openness: It is a W3C standard, endorsed by software industry market leaders.

Extensibility: It is extensible because it has no fixed set of tags. You can define them as
you need.

Self-descriptive: XML documents do not need special schema set-up like traditional
databases to store data. XML documents can be stored without such definitions, because
they contain metadata in the form of tags and attributes.

Scalable: XML is not in binary format so you can create and edit files with anything and it is
also easy to debug.

Fast access: XML documents are arranged in hierarchical form so it is comparatively faster.

A syntactically correct document is called well formed XML document. A well formed XML
document must follow the XML?s basic rules of syntax:

o It must have a closing tag.


o The closing tag must exactly match the open tag: XML is case sensitive.
o All elements should be included within a single root tag.
o Child elements must be closed within parent tag.
o A structurally correct element is called a valid XML document. It should follow some
predefined rules of a specific type of document. These rules determine the type of
data that each part of the document can contain. These rules can be written by the
author of an XML document or someone other.

o Note: A valid XML document may be well-formed but a well-formed XML document
may not be valid.

2) How XML is different from HTML?


HTML stands for Hyper Text Markup Language while XML stands for eXtensible Markup
Language. The key differences between HTML and XML are given below:
No. HTML XML

1) HTML is used to display XML is a software and hardware independent


data and focuses on how tool used to transport and store data. It
data looks. focuses on what data is.

2) HTML is a markup XML provides a framework to define


language itself. markup languages.

3) HTML is not case XML is case sensitive.


sensitive.

4) HTML is a presentation XML is neither a presentation language nor a


language. programming language.

What is DTD?
DTD stands for Document Type Definition. It defines a leading building block of an XML
document. It defines:

o Names of elements
o How and where they can be used
o Element attributes
o Proper nesting

11) How can you apply a DTD to an XML document?


To apply a DTD to an XML document, you can:

o Use the DTD element definition within the XML document itself.
o Provide a DTD as a separate file and reference its name in XML document.

12) What are the basic rules to write XML document?


You should consider the following rules to write an XML document.
o It should have a root element.
o All tags must be closed.
o Spaces are not allowed in tag names.
o All tags must be nested properly.
o XML tags are case sensitive.
o Use the attribute values within quotes.
o Whitespace is preserved in XML.

21) What is XML data binding? Why is it used?


XML data binding is the process of representing the information in an XML document as an
object in computer memory.

XML data binding is used to short your development effort, simplify maintenance, increase
reliability. It saves your development time and money. It makes working with XML data
very intuitive.

22) What is XML encoding error?


There are two types of XML encoding errors:

1. An invalid character was found in text content.


2. Switching from current encoding to specified encoding not supported.

These errors occur because XML document can contain non ASCII characters like Norwegian
and French. These errors can be avoided by specifying the XML encoding Unicode.

23) What are the different XML API's?


Tree-based API: It compiles an XML document in a tree like structure and loads it into the
memory. You can traverse and change the tree structure. Tree based API's are useful for a
wide range of applications. Example of tree-based API is DOM parser.

Event-based API: An event based API provides the reports to an application about the
parsing event. It uses a set of built-in call back functions. Example of event-based API is
SAX parser.

XML Schema
What is XML schema
XML schema is a language which is used for expressing constraint about XML documents.
There are so many schema languages which are used now a days for example Relax- NG
and XSD (XML schema definition).

An XML schema is used to define the structure of an XML document. It is like DTD but
provides more control on XML structure.

Checking Validation
An XML document is called "well-formed" if it contains the correct syntax. A well-formed
and valid XML document is one which have been validated against Schema.

Visit http://www.xmlvalidation.com to validate the XML file against schema or DTD.

XML Schema Example


Let's create a schema file.

employee.xsd

1. <?xml version="1.0"?>
2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3. targetNamespace="http://www.javatpoint.com"
4. xmlns="http://www.javatpoint.com"
5. elementFormDefault="qualified">
6.
7. <xs:element name="employee">
8. <xs:complexType>
9. <xs:sequence>
10. <xs:element name="firstname" type="xs:string"/>
11. <xs:element name="lastname" type="xs:string"/>
12. <xs:element name="email" type="xs:string"/>
13. </xs:sequence>
14. </xs:complexType>
15. </xs:element>
16.
17. </xs:schema>
1. <?xml version="1.0"?>
2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3. targetNamespace="http://www.javatpoint.com"
4. xmlns="http://www.javatpoint.com"
5. elementFormDefault="qualified">
6.
7. <xs:element name="employee">
8. <xs:complexType>
9. <xs:sequence>
10. <xs:element name="firstname" type="xs:string"/>
11. <xs:element name="lastname" type="xs:string"/>
12. <xs:element name="email" type="xs:string"/>
13. </xs:sequence>
14. </xs:complexType>
15. </xs:element>
16.
17. </xs:schema>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://w
targetNamespace="http://www.j
xmlns="http://www.javatpoint.co
elementFormDefault="qualified">

Let's see the xml file using XML schema or XSD file.

employee.xml

1. <?xml version="1.0"?>
2. <employee
3. xmlns="http://www.javatpoint.com"
4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5. xsi:schemaLocation="http://www.javatpoint.com employee.xsd">
6.
7. <firstname>vimal</firstname>
8. <lastname>jaiswal</lastname>
9. <email>vimal@javatpoint.com</email>
10. </employee>
1. <?xml version="1.0"?>
2. <employee
3. xmlns="http://www.javatpoint.com"
4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5. xsi:schemaLocation="http://www.javatpoint.com employee.xsd">
6.
7. <firstname>vimal</firstname>
8. <lastname>jaiswal</lastname>
9. <email>vimal@javatpoint.com</email>
10. </employee>
<?xml version="1.0"?>
<employee
xmlns="http://www.javatpoint.co
xmlns:xsi="http://www.w3.org/2
xsi:schemaLocation="http://www

Test it Now

Description of XML Schema


<xs:element name="employee"> : It defines the element name employee.

<xs:complexType> : It defines that the element 'employee' is complex type.

<xs:sequence> : It defines that the complex type is a sequence of elements.

<xs:element name="firstname" type="xs:string"/> : It defines that the element


'firstname' is of string/text type.

<xs:element name="lastname" type="xs:string"/> : It defines that the element


'lastname' is of string/text type.

<xs:element name="email" type="xs:string"/> : It defines that the element 'email' is


of string/text type.

XML Schema Data types


There are two types of data types in XML schema.

1. simpleType
2. 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.

XML Validation
A well formed XML document can be validated against DTD or Schema.

A well-formed XML document is an XML document with correct syntax. It is very necessary
to know about valid XML document before knowing XML validation.

Valid XML document


It must be well formed (satisfy all the basic syntax condition)

It should be behave according to predefined DTD or XML schema

Rules for well formed XML


o It must begin with the XML declaration.
o It must have one unique root element.
o All start tags of XML documents must match end tags.
o XML tags are case sensitive.
o All elements must be closed.
o All elements must be properly nested.
o All attributes values must be quoted.
o XML entities must be used for special characters.

XML DTD
A DTD defines the legal elements of an XML document
In simple words we can say that a DTD defines the document structure with a list of legal
elements and attributes.

XML schema is a XML based alternative to DTD.

Actually DTD and XML schema both are used to form a well formed XML document.

We should avoid errors in XML documents because they will stop the XML programs.

XML schema
It is defined as an XML language

Uses namespaces to allow for reuses of existing definitions

It supports a large number of built in data types and definition of derived data types

XML DTD

What is DTD
DTD stands for Document Type Definition. It defines the legal building blocks of an XML
document. It is used to define document structure with a list of legal elements and
attributes.

Purpose of DTD
Its main purpose is to define the structure of an XML document. It contains a list of legal
elements and define the structure with the help of them.

Checking Validation
Before proceeding with XML DTD, you must check the validation. An XML document is called
"well-formed" if it contains the correct syntax.

A well-formed and valid XML document is one which have been validated against DTD.

Visit http://www.xmlvalidation.com to validate the XML file.


Valid and well-formed XML document with DTD
Let's take an example of well-formed and valid XML document. It follows all the rules of
DTD.

employee.xml

1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <firstname>vimal</firstname>
5. <lastname>jaiswal</lastname>
6. <email>vimal@javatpoint.com</email>
7. </employee>
1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <firstname>vimal</firstname>
5. <lastname>jaiswal</lastname>
6. <email>vimal@javatpoint.com</email>
7. </employee>

In the above example, the DOCTYPE declaration refers to an external DTD file. The content
of the file is shown in below paragraph.

employee.dtd

1. <!ELEMENT employee (firstname,lastname,email)>


2. <!ELEMENT firstname (#PCDATA)>
3. <!ELEMENT lastname (#PCDATA)>
4. <!ELEMENT email (#PCDATA)>

1. <!ELEMENT employee (firstname,lastname,email)>


2. <!ELEMENT firstname (#PCDATA)>
3. <!ELEMENT lastname (#PCDATA)>
4. <!ELEMENT email (#PCDATA)>

Description of DTD
<!DOCTYPE employee : It defines that the root element of the document is employee.

<!ELEMENT employee: It defines that the employee element contains 3 elements


"firstname, lastname and email".
<!ELEMENT firstname: It defines that the firstname element is #PCDATA typed. (parse-
able data type).

<!ELEMENT lastname: It defines that the lastname element is #PCDATA typed. (parse-
able data type).

<!ELEMENT email: It defines that the email element is #PCDATA typed. (parse-able data
type).

XML DTD with entity declaration


A doctype declaration can also define special strings that can be used in the XML file.

An entity has three parts:

1. An ampersand (&)
2. An entity name
3. A semicolon (;)

Syntax to declare entity:

1. <!ENTITY entity-name "entity-value">


1. <!ENTITY entity-name "entity-value">

Let's see a code to define the ENTITY in doctype declaration.

author.xml

1. <?xml version="1.0" standalone="yes" ?>


2. <!DOCTYPE author [
3. <!ELEMENT author (#PCDATA)>
4. <!ENTITY sj "Sonoo Jaiswal">
5. ]>
6. <author>&sj;</author>
1. <?xml version="1.0" standalone="yes" ?>
2. <!DOCTYPE author [
3. <!ELEMENT author (#PCDATA)>
4. <!ENTITY sj "Sonoo Jaiswal">
5. ]>
6. <author>&sj;</author>
7. In the above example, sj is an entity that is used inside the author element. In such
case, it will print the value of sj entity that is "Sonoo Jaiswal".
8. Note: A single DTD can be used in many XML files.

CDATA vs PCDATA

CDATA
CDATA: (Unparsed Character data): CDATA contains the text which is not parsed further in
an XML document. Tags inside the CDATA text are not treated as markup and entities will
not be expanded.

Let's take an example for CDATA:

1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <![CDATA[
5. <firstname>vimal</firstname>
6. <lastname>jaiswal</lastname>
7. <email>vimal@javatpoint.com</email>
8. ]]>
9. </employee>
1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <![CDATA[
5. <firstname>vimal</firstname>
6. <lastname>jaiswal</lastname>
7. <email>vimal@javatpoint.com</email>
8. ]]>
9. </employee>
Test it Now

In the above CDATA example, CDATA is used just after the element employee to make the
data/text unparsed, so it will give the value of employee:

<firstname>vimal</firstname><lastname>jaiswal</lastname><email>vimal@javatpoi
nt.com</email>
PCDATA
PCDATA: (Parsed Character Data): XML parsers are used to parse all the text in an XML
document. PCDATA stands for Parsed Character data. PCDATA is the text that will be parsed
by a parser. Tags inside the PCDATA will be treated as markup and entities will be
expanded.

In other words you can say that a parsed character data means the XML parser examine the
data and ensure that it doesn't content entity if it contains that will be replaced.

Let's take an example:

1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <firstname>vimal</firstname>
5. <lastname>jaiswal</lastname>
6. <email>vimal@javatpoint.com</email>
7. </employee>
1. <?xml version="1.0"?>
2. <!DOCTYPE employee SYSTEM "employee.dtd">
3. <employee>
4. <firstname>vimal</firstname>
5. <lastname>jaiswal</lastname>
6. <email>vimal@javatpoint.com</email>
7. </employee>
Test it Now

In the above example, the employee element contains 3 more elements 'firstname',
'lastname', and 'email', so it parses further to get the data/text of firstname, lastname and
email to give the value of employee as:

vimal jaiswal vimal@javatpoint.com


next →← prev

XML DOM

What is XML DOM


DOM is an acronym stands for Document Object Model. It defines a standard way to
access and manipulate documents. The Document Object Model (DOM) is a programming
API for HTML and XML documents. It defines the logical structure of documents and the
way a document is accessed and manipulated.

As a W3C specification, one important objective for the Document Object Model is to
provide a standard programming interface that can be used in a wide variety of
environments and applications. The Document Object Model can be used with any
programming language.

XML DOM defines a standard way to access and manipulate XML documents.

What does XML DOM


The XML DOM makes a tree-structure view for an XML document.

We can access all elements through the DOM tree.

We can modify or delete their content and also create new elements. The elements, their
content (text and attributes) are all known as nodes.

For example, consider this table, taken from an HTML document:

1. <TABLE>
2. <ROWS>
3. <TR>
4. <TD>A</TD>
5. <TD>B</TD>
6. </TR>
7. <TR>
8. <TD>C</TD>
9. <TD>D</TD>
10. </TR>
11. </ROWS>
12. </TABLE>
1. <TABLE>
2. <ROWS>
3. <TR>
4. <TD>A</TD>
5. <TD>B</TD>
6. </TR>
7. <TR>
8. <TD>C</TD>
9. <TD>D</TD>
10. </TR>
11. </ROWS>
12. </TABLE>

The Document Object Model represents this table like this:

XML DOM Example : Load XML File


Let's take an example to show how an XML document ("note.xml") is parsed into an XML
DOM object.
This example parses an XML document (note.xml) into an XML DOM object and extracts
information from it with JavaScript.

Let's see the XML file that contains message.

note.xml

1. <?xml version="1.0" encoding="ISO-8859-1"?>


2. <note>
3. <to>sonoojaiswal@javatpoint.com</to>
4. <from>vimal@javatpoint.com</from>
5. <body>Hello XML DOM</body>
6. </note>
1. <?xml version="1.0" encoding="ISO-8859-1"?>
2. <note>
3. <to>sonoojaiswal@javatpoint.com</to>
4. <from>vimal@javatpoint.com</from>
5. <body>Hello XML DOM</body>
6. </note>

Let's see the HTML file that extracts the data of XML document using DOM.

xmldom.html

1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>Important Note</h1>
5. <div>
6. <b>To:</b> <span id="to"></span><br>
7. <b>From:</b> <span id="from"></span><br>
8. <b>Message:</b> <span id="message"></span>
9. </div>
10. <script>
11. if (window.XMLHttpRequest)
12. {// code for IE7+, Firefox, Chrome, Opera, Safari
13. xmlhttp=new XMLHttpRequest();
14. }
15. else
16. {// code for IE6, IE5
17. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
18. }
19. xmlhttp.open("GET","note.xml",false);
20. xmlhttp.send();
21. xmlDoc=xmlhttp.responseXML;
22. document.getElementById("to").innerHTML=
23. xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
24. document.getElementById("from").innerHTML=
25. xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
26. document.getElementById("message").innerHTML=
27. xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
28. </script>
29. </body>
30. </html>
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>Important Note</h1>
5. <div>
6. <b>To:</b> <span id="to"></span><br>
7. <b>From:</b> <span id="from"></span><br>
8. <b>Message:</b> <span id="message"></span>
9. </div>
10. <script>
11. if (window.XMLHttpRequest)
12. {// code for IE7+, Firefox, Chrome, Opera, Safari
13. xmlhttp=new XMLHttpRequest();
14. }
15. else
16. {// code for IE6, IE5
17. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
18. }
19. xmlhttp.open("GET","note.xml",false);
20. xmlhttp.send();
21. xmlDoc=xmlhttp.responseXML;
22. document.getElementById("to").innerHTML=
23. xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
24. document.getElementById("from").innerHTML=
25. xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
26. document.getElementById("message").innerHTML=
27. xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
28. </script>
29. </body>
30. </html>
Test it Now

Output:

Important Note
To: sonoojaiswal@javatpoint.com
From: vimal@javatpoint.com
Message: Hello XML DOM

XML DOM Example : Load XML String


This example parses an XML string into an XM DOM object and then extracts some
information from it with a JavaScript.

Let's see the HTML file that extracts the data of XML string using DOM.

xmldom.html

1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>Important Note2</h1>
5. <div>
6. <b>To:</b> <span id="to"></span><br>
7. <b>From:</b> <span id="from"></span><br>
8. <b>Message:</b> <span id="message"></span>
9. </div>
10. <script>
11. txt1="<note>";
12. txt2="<to>Sania Mirza</to>";
13. txt3="<from>Serena William</from>";
14. txt4="<body>Don't forget me this weekend!</body>";
15. txt5="</note>";
16. txt=txt1+txt2+txt3+txt4+txt5;
17.
18. if (window.DOMParser)
19. {
20. parser=new DOMParser();
21. xmlDoc=parser.parseFromString(txt,"text/xml");
22. }
23. else // Internet Explorer
24. {
25. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
26. xmlDoc.async=false;
27. xmlDoc.loadXML(txt);
28. }
29. document.getElementById("to").innerHTML=
30. xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
31. document.getElementById("from").innerHTML=
32. xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
33. document.getElementById("message").innerHTML=
34. xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
35. </script>
36. </body>
37. </html>
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>Important Note2</h1>
5. <div>
6. <b>To:</b> <span id="to"></span><br>
7. <b>From:</b> <span id="from"></span><br>
8. <b>Message:</b> <span id="message"></span>
9. </div>
10. <script>
11. txt1="<note>";
12. txt2="<to>Sania Mirza</to>";
13. txt3="<from>Serena William</from>";
14. txt4="<body>Don't forget me this weekend!</body>";
15. txt5="</note>";
16. txt=txt1+txt2+txt3+txt4+txt5;
17.
18. if (window.DOMParser)
19. {
20. parser=new DOMParser();
21. xmlDoc=parser.parseFromString(txt,"text/xml");
22. }
23. else // Internet Explorer
24. {
25. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
26. xmlDoc.async=false;
27. xmlDoc.loadXML(txt);
28. }
29. document.getElementById("to").innerHTML=
30. xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
31. document.getElementById("from").innerHTML=
32. xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
33. document.getElementById("message").innerHTML=
34. xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
35. </script>
36. </body>
37. </html>
Test it Now

Output:

Important Note2

To: Sania Mirza


From: Serena William
Message: Don't forget me this weekend!

XML CSS

Purpose of CSS in XML


CSS (Cascading Style Sheets) can be used to add style and display information to an XML
document. It can format the whole XML document.

How to link XML file with CSS


To link XML files with CSS, you should use the following syntax:

1. <?xml-stylesheet type="text/css" href="cssemployee.css"?>


1. <?xml-stylesheet type="text/css" href="cssemployee.css"?>
XML CSS Example
Let's see the css file.

cssemployee.css

1. employee
2. {
3. background-color: pink;
4. }
5. firstname,lastname,email
6. {
7. font-size:25px;
8. display:block;
9. color: blue;
10. margin-left: 50px;
11. }
1. employee
2. {
3. background-color: pink;
4. }
5. firstname,lastname,email
6. {
7. font-size:25px;
8. display:block;
9. color: blue;
10. margin-left: 50px;
11. }

Let's create the DTD file.

employee.dtd

1. <!ELEMENT employee (firstname,lastname,email)>


2. <!ELEMENT firstname (#PCDATA)>
3. <!ELEMENT lastname (#PCDATA)>
4. <!ELEMENT email (#PCDATA)>
1. <!ELEMENT employee (firstname,lastname,email)>
2. <!ELEMENT firstname (#PCDATA)>
3. <!ELEMENT lastname (#PCDATA)>
4. <!ELEMENT email (#PCDATA)>
Let's see the xml file using CSS and DTD.

employee.xml

1. <?xml version="1.0"?>
2. <?xml-stylesheet type="text/css" href="cssemployee.css"?>
3. <!DOCTYPE employee SYSTEM "employee.dtd">
4. <employee>
5. <firstname>vimal</firstname>
6. <lastname>jaiswal</lastname>
7. <email>vimal@javatpoint.com</email>
8. </employee>
1. <?xml version="1.0"?>
2. <?xml-stylesheet type="text/css" href="cssemployee.css"?>
3. <!DOCTYPE employee SYSTEM "employee.dtd">
4. <employee>
5. <firstname>vimal</firstname>
6. <lastname>jaiswal</lastname>
7. <email>vimal@javatpoint.com</email>
8. </employee>
Test it Now

CSS is not generally used to format XML file. W3C recommends XSLT instead of CSS.

XML Database
XML database is a data persistence software system used for storing the huge amount of
information in XML format. It provides a secure place to store XML documents.

You can query your stored data by using XQuery, export and serialize into desired format.
XML databases are usually associated with document-oriented databases.

Types of XML databases


There are two types of XML databases.

1. XML-enabled database
2. Native XML database (NXD)
XML-enable Database
XML-enable database works just like a relational database. It is like an extension provided
for the conversion of XML documents. In this database, data is stored in table, in the form
of rows and columns.

Native XML Database


Native XML database is used to store large amount of data. Instead of table format, Native
XML database is based on container format. You can query data by XPath expressions.

Native XML database is preferred over XML-enable database because it is highly capable to
store, maintain and query XML documents.

Let's take an example of XML database:

1. <?xml version="1.0"?>
2. <contact-info>
3. <contact1>
4. <name>Vimal Jaiswal</name>
5. <company>SSSIT.org</company>
6. <phone>(0120) 4256464</phone>
7. </contact1>
8. <contact2>
9. <name>Mahesh Sharma </name>
10. <company>SSSIT.org</company>
11. <phone>09990449935</phone>
12. </contact2>
13. </contact-info>
1. <?xml version="1.0"?>
2. <contact-info>
3. <contact1>
4. <name>Vimal Jaiswal</name>
5. <company>SSSIT.org</company>
6. <phone>(0120) 4256464</phone>
7. </contact1>
8. <contact2>
9. <name>Mahesh Sharma </name>
10. <company>SSSIT.org</company>
11. <phone>09990449935</phone>
12. </contact2>
13. </contact-info>

In the above example, a table named contacts is created and holds the contacts (contact1
and contact2). Each one contains 3 entities name, company and phone.

You might also like