You are on page 1of 23

XML

Extensible Markup Language


 It is a cross platform tool or a language to achieve data
transfer between the cross platform.
 Note  1.XML is not a replacement for HTML.
2. It is used to present the data in a formatted matter.
3.XML is used to represent the data.
4.XML is used to represent the data and it is not having
any capability to perform any tasks on its own.Always
an application is required in order to work with the
XML documents.
 For eg 
<employee>
<empno>10</empno>
<ename>Sai</ename>
<sal> 9500</sal>
</employee>
 The above XML document might give an
illusion stating the information belongs to
an employee but still the XML doc. Cant do
any thing on its own for the system it is
considered as a same information wrapped
in the user defined things.
XML

Well Formed XML doc Valid XML doc

 Well formed XML doc  it is used for


representing the data only.
 Valid XML doc  it is used for representing the
data along with its definitions.
 Where the definitions of the XML document can
be provided using either the Data Type Definitions
(DTD) or XML Schema Definitions(XSD) file
Rules for writing a Well Formed XML doc
 The extension for the file should be XML.
 XML documents are case sensitive files and hence the tags and
the attribute values of the documents should be maintained in
proper case.
 XML document should have atleast one root element which can
have one or more Child elements.
 Structure of a Well Formed XML doc
 <rootElement attributeName=“value”>
<childElement>
<subChildElement>----- </subChildElement>
</childElement>
</rootElement>
Rules for writing a Well Formed XML doc

 There are no predefined tags provided for the XMl documents and
hence the XML doc will be defined based on the user defined tags
only.
 Where a tag is a string which will be enclosed within an angular
basis.
 What ever the tags that are opened in an XML document it is
mandatory to close those tags.
 When ever the XML document is defined using a hierarchy of
elements then it is mandatory to close the elements in the same
hierarchy.
Valid XML document

 When ever the XML document is designed


based on the DTD file then it is said to be
valid XML document.
Data Type Definitions

 Itis used to provide the definitions for the data to


be used or to be provided in the XML document.
 Where the definitions includes
 The no of times the elements to be used in the
document.
 if any additional information has to be provided
for the elements used in the documents.
 It can also be used to provide the definitions for
the named entities to be used in the document.
 In order to define a DTD file it is been defined with support of 3
Tags 
1] ELEMENT  it is used to specify the element to be used in
the XML document and their occurrences in that document.
Syntax  <! ELEMENT elementName (content[wild card])>
where wild card is an optional value which is used to specify the
no of occurrences of the element within the document.

Wild card Min Max


Occurrences Occurrences
? 0 1

+ 1 Any

* 0 any
 For eg:
<! ELEMENT Employees(emp +)>
<! ELEMENT Emp(empno,ename,sal) >
<! ELEMENT empno(#PCDATA)>
<! ELEMENT ename(#PCDATA)>
<! ELEMENT esal(#PCDATA)>
Based on the above defintions an XML file has to be designed.
<Employees>
<Emp>
<empno>101</empno>
<ename>Kamala</ename>
<sal>10000</sal>
</Emp>
<Emp>
-----
-----
</Emp>
</Employees>
 ATTLIST  It is used for providing additional information
for the elements placed on the XML document.
Syntax 
<!ATTLIST elementName attributeName(“DefaultValue”)>
for e.g.:-
<!ATTLIST emp deptno(“10”)>
XML doc 
<Employees>
<Emp deptno=“10”>
----
----
</Emp>
</Employees>
 Note  there is no specification which specifies to use an
attribute or an element within the XML document.
For eg XML Documents using elements
<Employees>
<Emp>
<empno>1001</empno>
<ename>Sudhir</ename>
<sal>1000</sal>
</Emp>
</Employees>
XML doc using Attribute Information
<Employees>
<Emp empno=“1001” ename=“sudhir” sal=“10000” />
-----------------------------
</Employees>
Points to remember where attribute Method
should not be used
 When ever an element has to support multiple values then
attributes can’t be used,since a single attribute can accept only a
single value at a time.
 Whenever the information on the data for an element should be
nested then attribute information cant be used.
 .net provides rich class libraries in order to integrate XML
documents defined using elements and hence it reduces the
burden of the programmer to integrate XML documents within
.net
 Note  dot net provides class libraries to work with XML
documents defined using attributes but still the programming will
become complex.
Entity
 Entity  It is used to define a user specific named entities
which can be used in the XML document.
Note  when ever a named entity is used within a XML
document then the value of the named entity will be
substituted as a macro substitution within the XML
document.
<!ENTITY entityName “Value”>
for e.g
<!ENTITY SL “sudhironline”>
note  when ever in a XML document &SL; is used then
in that position the value “sudhironline” will be
substituted
Entity

 Note  by default XML document will support


the following main entities 
 &lt  it stands for less than
&gt  it stands for greater than
&amp  it stands for ampersand
&apos  it stands for apostaphe
&quot  it stands for quotation.
A DTD file definition can be binded to the XML
Document in 2 ways 
 Internal DTD Binding  when ever the data type
definitions are defined with the data within a XML
document it is said to be internal DTD for e.g
<!DOCTYPE [ELEMENT Definition
------
------] >
<RootElement>
<Childelement>
------------------
------------------
</Childelement>

</RootElement>
 External DTD Binding  when ever the data type
definitions are specified in a DTD file and if it has been
explicitly binded to the XML document then it is said to
be external DTD binding.
Syntax  to bind a DTD file to the XML Document
<!DOCTYPE rootElementName SYSTEM/PUBLIC
“path of DTDfile/URL “>
note  if the data type definition file is present in the
local drives of a system then
<!DOCTYPE Employees SYSTEM “c:\emp.dtd”>

If the DTD file is present on a web then


<!DOCTYPE Employees PUBLIC
http://localhost/emp.dtd>
PARSERS

X
M
L
XML Application
P
Document A
R
S
E
R

 It acts like a compiler which is used for parsing the XML


document such that its data can be represented on to the
application.
 XML Parser is of 2 types
1] DOM [ Document Object Model] Parser
if used for parsing the XML document then it compiles the
entire XML document and the result of it will be maintained
temporarily as a cache,information such that the data can be
projected or used within the application
 DOM parsers is of 2 types 
1.Non Validating DOM Parser
2.Validating DOM parser
 Non Validating DOM Parser  it is used for parsing the well
formed XML Document by verifying only the rules of the XML
Document.
Note  if an non validating DOM Parser is used for parsing a
valid XML document then if the document violates the
definitions binded to the XML document still the data will be
parsed and it will be loaded on to the memory such that the
applications can use the data.
 Validating DOM Parser  it is used for parsing a
valid XML document.
Note  if the document violates the definitions
binded to it then the data will not be parsed and
the system will raise an compilation error.
Note  by default all the latest browsers are
provided with non-violating DOM parsers.
 SAX Parser [ simple API for XML parser ]
It is an event based parser which parses only the data which has
been requested by the user and hence it is also called as event
based parser.
System.Data

Data Set

Write XML

Write XML Schema

Read XML

Read XML Schema


 Write XML  it is used to write the data present in
the data member of dataset as a data for the XML
document.
 Syntax  writexml(filename[,mode])
 Where mode can be
IgnoreSchema(default mode)
if used then only the data present in the dataset will
be written into the XML document.
WriteSchema
if used then the data present in the data members
of dataset will be written on to the XML
document,with its schema definitions
Diffgram
if used then if any manipulations are performed
then it will maintain the new data along with the
older.
 WriteXMLSchema 
it is used to write only the schema definitions for the
data present in the datamembers of dataset.
 ReadXML 
it is used to read the data present in the XML
document and it will store that data on to the dataset
with the support of data members.
Note  the parentElement present in the XML doc
will be considered as a datamember in dataset.
 ReadXMLSchema 
it is used to read only the schema definitions of the
data present in the XML doc.

You might also like