XML in Unit-1
XML in Unit-1
XML in Unit-1
XML
Introduction to XML:
XML stands for eXtensible Markup Language and is a text-based markup language derived from
Standard Generalized Markup Language (SGML). The primary purpose of this standard is to provide way to
store self describing data easily. Self-describing data are those that describe both their structure and their
content. But, HTML documents describe how data should appear on the browsers screen and no
information about the data. XML documents, on the other hand describe the meaning of data. The content
and structure of XML documents are accessed by software module called XML processor.
XML Characteristics:
1. XML is extensible : XML essentially allows you to create your own language, or tags, that suits
your application.
2. XML separates data from presentation : XML allows you to store content with regard to how it
will be presented.
3. XML is a public standard : XML was developed by an organization called the World Wide Web
Consortium (W3C) and available as an open standard.
XML Usage:
A short list of XML's usage says it all
XML can work behind the scene to simplify the creation of HTML documents for large web sites.
XML can be used to exchange of information between organizations and systems.
XML can be used for offloading and reloading of databases.
XML can be used to store and arrange data in a way that is customizable for your needs.
XML can easily be mixed with stylesheets to create almost any output desired.
XML features:
XML allows the user to define his own tags and his own document structure.
XML document is pure information wrapped in XML tags.
XML is a text based language, plain text files can be used to share data.
XML provides a software and hardware independent way of sharing data.
1. Prolog:
This part of XML document may contain following parts: XML declaration, Optional processing
instructions, Comments and Document Type Declaration
XML Declaration:
Every XML document should start with one-line XML declaration which describes document itself. The
XML declaration is written as below:
Syn: <?xml version="1.0" encoding="UTF-8"?>
Where version is the XML version and encoding specify the character encoding used in the document. UTF-
8 stands for Unicode Transformation Format is used for set of ASCII characters. It also have standalone
attribute indicates whether the document can be processed as standalone document or is dependent on other
document like Document Type Declaration(DTD).
Syn: <?xml version="1.0" encoding="UTF-8" standalone=”yes|no”?>
Processing Instruction:
Processing Instructions starts with left angular bracket along with question mark(<?),ending with
question mark followed by the right angular bracket(?>). These parameters instruct the application about
how to interpret XML document. XML parser’s do not take care of processing instructions and are not text
portion of XML document.
Ex: <?xsl-stylesheet href=”simple.xsl” type=”text/xsl”?>
www.Jntufastupdates.com 1
Page|2
Comments:
Like HTML, comments may use anywhere in XML documents. An XML comments starts with <!—and
ends with -->. Everything with in these will be ignored by the parsers and will not be parsed.
Syn: <!-- this is comments -->
Following points should be remembered while using comments: do not use double hyphens, never place
inside entity declaration or within any tag, never place before XML declaration
Document Type Declaration(DTD):
XML allows to create new tags and have meaning if it has some logical structure created using set of
related tags. <!DOCTYPE > is used to specify the logical structure of XML document by imposing
constraints on what tags can be used and where. DTD may contain Name of root element, reference to
external DTD, element and entity declarations.
2. Body:
This portion of XML document contains textual data marked up by tags. It must have one element
called Document or Root element, which defines content in the XML document. Root element must be the top-
level element in the document hierarchy and there can be one and only one root element.
Ex: <?xml version=”1.0”?>
<book>
<title>WT</title>
<author>Uttam Roy</author>
<price>500</price>
</book>
In this document, the name of root element id <book> which contains sub tags <title>, <author> and
<price>. Each of these tags contains text “WT”, “Uttam Roy” and “500” respectively.
XML Elements
An XML element consists of starting tag, an ending tag and its contents and attributes. The contents
may be simple text or other element or both. XML tags are very much similar to that of HTML tags. A tag
begins with less than(<) and ends with greater than(>) character. It takes the form <tag-name> and must
have corresponding ending tag(</tag-name>). An element consists of opening tag, closing tag and contents.
Few tag may not contain any content and hence know as Empty elements. According to the well-formedness
constraint, every XML element must have closing tag. XML provides two ways for XML empty elements as
follows:
Syn: <br></br> or <br />
Following are the rules that need to be followed for XML elements:
An element name can contain any alphanumeric characters. The only punctuation allowed in names
are the hyphen ( - ), under-score ( _ ) and period ( . )
Names are case sensitive. For example Address, address, ADDRESS are different names
Element start and end tag should be identical
An element which is a container can contain text or elements as seen in the above example
Attributes: Attributes are used to describe elements or to provide more information about elements. They
appear in the starting tag of element. The syntax of specifying an attribute in element is:
Syn: <element-name attribute-name=”value”>…</elment-name>
Ex: <employee gener=”male”>ABCD</employee>
There is no strict rules that describes when to use elements and when to use attributes. However, it is
recommended not to use attributes as far as possible due to following reasons:
Too many attributes reduce readability of XML document
Attributes cannot contain multiple values, but elements can
Attributes are not easily extendable
Attributes cannot represent logical structure, but elements together with their child elements can
Attributes are difficult to access by parsers
www.Jntufastupdates.com 2
Page|3
Well-formed XML:
An XML document is said to be well-formed if it contains text and tags that conform with the basic XML well-
formedness constraints. XML can extend existing documents by creating new elements that fit their
applications. The only thing is to remember the well-formedness constraints. The following rules must be
followed by XML documents:
An XML document must have one and only one root element
All tags must be closed
All tags must be properly nested
XML tags are case-sensitive
Attributes must always be quoted
Certain characters are reserved for processing like pre-defined entities
Pre-defined Entities: W3C specification defined few entities each of which represents a special character
that cannot be used in XML document directly. All XML processors must recognize those entities, whether
they are declared or not.
Entity Name Entity Number Description Character
< < Less than <
> > Greater than >
& & Amprersand &
" " Quotation mark “
' ' Apostrophe ‘
Valid XML
Well-formed XML documents obey only basic well formedness constraints. So, valid XML documents are
those that are well formed and comply with rules specified in DTC or Schema.
Name Space
XML was developed to be used by many applications. If many applications want to communicate using
XML documents, problems may occur. In XML document, element and attribute names are selected by
developers. In some cases two different documents may have same root element. For example, both
client.xml and server.xml contains same root tag <config> as shown below.
Client.xml Server.xml
<config> <config>
<version>1.0</version> <version>1.0</version>
</config> </config>
XML namespace provides simple, straightforward way to distinguish between element names in XML
document. Namespace suggests to use prefix with every element as follows:
Client.xml Server.xml
<c:config> <s:config>
<c:version>1.0</c:version> <s:version>1.0</s:version>
</c:config> </s:config>
Uniform Resource Identifier(URI) is used to guarantee the prefixes used by different developers. In general
URL are used to choose unique name. But, URL must be prefixed for each tag instead of them we use
prefix. Prefixes are just shorthand placeholders of URLs. Association of prefix and URL is done in the
starting tag using reserved XML attribute xmlns.
Syn: xmlns:prefix=”URI”
Name Space Rules: The xmlns attribute identifies namespace and makes association between prefix and
created namespace. Many prefixes may be associated with one namespace.
www.Jntufastupdates.com 3
Page|4
Default Namespace: Namespaces may not have their associated prefixes and are called default namespace.
In such cases, a blank prefix is assumed for element and all of its descendants.
www.Jntufastupdates.com 4
Page|5
<author>Uttam Roy</author>
<publisher>Oxford</publisher>
<price>500</price>
</book>
<book>
<title>AJ</title>
<author>Schildt</author>
<publisher>TMH</publisher>
<price>200</price>
</book>
</bookstore>
2. External DTD:
Another way of connection DTD to XML document is to reference it with in XML document i.e.
create separate document, put DTD information there and point to it from XML document. The general
syntax for external DTD is.
Syn: <!DOCTYPE root-element SYSTEM | PUBLIC "uri">
Where uri is the Uniform Resource Identifier of the .dtd file. This declaration states that we are going to
define structure of root-element of XML document and its definition can be found from uri specified like
book.dtd. both xml and dtd files should be kept in same directory.
Ex:
book.xml book.dtd
<?xml version="1.0" ?> <!ELEMENT bookstore (book*)>
<!DOCTYPE book SYSTEM "book.dtd"> <!ELEMENT book (title,author,price)>
<bookstore> <!ELEMENT title (#PCDATA)>
<book> <!ELEMENT author (#PCDATA)>
<title>WT</title> <!ELEMENT publisher (#PCDATA)>
<author>Uttam Roy</author> <!ELEMENT price (#PCDATA)>
<publisher>Oxford</publisher>
<price>500</price>
</book>
<book>
<title>AJ</title>
<author>Schildt</author>
<publisher>TMH</publisher>
<price>200</price>
</book>
</bookstore>
Location of DTD need not always be local file, it can be any valid URL. Following declaration for XHTML
uses PUBLIC DTD:
Syn: <!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 4.0 Transitional//EN’>
Disadvantage of using separate DTD is we have to deal with two documents.
3. Combining Internal and External DTD:
External DTD are useful for common rules for set of XML documents, whereas internal DTDs are beneficial
for defining customized rules for specific document. XML allows to combine both internal and external
DTD for complete collection of rules for given document. The general form of such DTD is:
Syn: <!DOCTYPE root-element SYSTEM | PUBLIC "uri" [ DTD declarations… ] >
Ex: <?xml version="1.0" ?>
<!DOCTYPE book SYSTEM "book.dtd"
[ <!ELEMENT excl ‘’>
]>
<msg>Hello, World! </msg>
www.Jntufastupdates.com 5
Page|6
DTD validation:
We'll use Java based DTD validator to validate the bookstore.xml against the books.dtd
DTDValidator.java
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class DTDValidator
{
public static void main(String[] args) {
try {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setValidating(true); // Default is false
Document d = f.newDocumentBuilder().parse(arg[0]);
}
catch (Exception e) { System.out.println(e.toString()); }
}
www.Jntufastupdates.com 6
Page|7
Attribute Declaration:
Attributes are used to associate name, value pairs with elements. They are useful when we want to provide
some additional information about elements content. The declaration starts with ATTLIST followed by
name of the element the attributes are associated with and declaration of individual declarations:
Syn: <!ATTLIST element-name attribute-name attribute-type default-vale>
Ex: <!ATTLIST employee geneder CDATA ‘male’/>
Here, ATTLIST must be in upper case. The default-value can be any of the following:
Default: in this case, attribute is optional and developer may or may not provide this attribute. When
attribute is declared with default value, the value of attribute is whatever value appears as attributes
content in instance document.
Ex: <!ATTLIST line width CDATA ‘100’/>
#REQUIRED: attribute must be specified with value every time enclosing element is listed
Ex: <!ATTLIST line width CDATA #RQUIRED />
#FIXED: attribute is optional and is used to ensure that the attributes are set to particular values.
Ex: <!ATTLIST line width CDATA #FIXED ‘50’/>
#IMPLIED: similar to that of default attribute except that no default value is provided by XML
Ex: <!ATTLIST line width CDATA ‘#IMPLIED’ />
Attribute types:
The attribute-type can be one among string or CDATA, tokenized and enumerated types.
String type: may take any literal string as value and can be declared using keyword CDATA. An
attribute of CDATA type can contain any character if it conforms to well formedness constraints.
Some it can contains escape characters like <, > etc.
Tokenized type: following tokenized types are available
o ID: it is globally unique identifier of attribute, this means value of ID attribute must not
appear more than once throughout the XML document and resembles primary key concept of
data base.
<!ATTLIST question no ID #REQUIRED>
o IDREF: similar to that of foreign key concept in databases and is used to establish
connections between elements. IDREF value of the attribute must refer to ID value declared
<!ATTLIST answer qno IDREF #REQUIRED>
o IDREFS: it allows a list of ID values separated by white spaces
<!ATTLIST answer qno IDREFS #REQUIRED>
o NMTOKEN: it restricts attributes value to one that is valid XML name means allows
punctuation marks and white spaces.
<!ATTLIST car serial NMTOKEN #REQUIRED>
o NMTOKENS: can contains same characters and white spaces as NMTOKEN. White space
includes one or more characters, carriage returns, line feeds, tabs
<!ATTLIST car serial NMTOKENS #REQUIRED>
o ENTITY: refers to external non parsed entities
<!ATTLIST car serial ENTITY #REQUIRED>
o ENTITIES: values of ENTITIES attribute may contain multiple entity names separated by
one or more white spaces
<!ATTLIST car serial ENTITIES #REQUIRED>
www.Jntufastupdates.com 7
Page|8
Enumerated type: enumerated attribute values are used when we want attribute value to be one of
fixed set of values. There are two kinds of enumerated types:
o Enumeration: attributes are defined by a list of acceptable values from which document
author must choose a value. The values are explicitly specified in declaration, separated by
pipe(|)
<!ATTLIST employee gender (male|female) #REQUIRED>
o Notation: it allows to use value that has been declared a NOTATION in DTD. Notation is
used to specify format of non-XML data and common used is to describe MIME types like
image/gif, image/jpeg etc.
<!NOTATION jpg SYSTEM ‘image/gif’>
<!ENTITY logo SYSTEM ‘logo.jpg’ NDATA jpg>
<!ATTLIST photo format NOTATION (jpg) #IMPLIED>
Entity Declaration:
Entities are variables that represent other values. If a text contains entities, the value of entity is
substituted by its actual value whenever the text is parsed. Entity must be defined in DTD declaration to use
custom entites in XML document. Built-in entities and character entities do not require any declaration.
There are two types of entity declarations: General entity and Paramter entity. Each type can be again Parsed
or Unparsed.
General and Parameter entities: General entities are used with in the document content. Parameter
entities are parsed entites used with in DTD. These two types of entites use different forms of
references and are recognized in different contexts. They occupy different namespaces
Parsed and Unparsed entities: Parsed entity is an entity whose content is parsed and checked for
well formedness constraint during parsing procedure. Unparsed entity is resource whose contents
may or may not be text and if text may not be XML. It means there are no constrainst on conetents of
unparsed entities. Each unparsed entity has associated notation, identified by name.
General Entity Declaration:
There are three kinds of general entitity declarations:
Internal parsed: an internal entity declaration has following form
Syn: <!ENTITY entity-name “entity-value”>
Ex: <!ENTITY UKR “Uttam Kumar Roy”>
The entity UKR can be referred in XML document as follows:
<author>&UKR;</author>
This will be interprested as : <author>Uttam Kumar Roy</author>
External parsed: external entities allow an XML document to refer to external resource.Parse
external entites refer to data that an XML parser has to parse and used for long replacement text
which is kept in another file. There are two type of external parsed entities: Public and Private.
Public external enties are identified by PUBLIC keyword and intended for general use. Private
external entites are identified by SYSTEM keyword and are intended for use by single author or
group of authors.
Syn: <!ENTITY entity-name SYSTRM | PUBLIC “URI”>
Ex: <!ENTITY author SYSTEM “author.xml”>
External unparsed: refer to data that an XML processor does not have to parse. For example,
there are numerious ASCII text files, JPRG photographs etc. None of theseare well formed XML.
Mechanism that XML suggests for embedding these files is enternal unparsed entity. They can be
either private or public.
Syn: <!ENTITY logo SYSTEM “logo.jpg” NDATA jpeg>
Parameter Entity Declaration:
DTD supports another kind of entity called parameter entity. It is used within DTD which allows to
assign collection of elements, attributes and attribute values to name and refer them using name instead of
explicitly listimg them every time they are used.
www.Jntufastupdates.com 8
Page|9
2. XML Schema:
XML Schema Definition commonly known as XSD, is a way to describe precisely the XML
language. XSD check the validity of structure and vocabulary of an XML document against the grammatical
rules of the appropriate XML language.An XML document can be defined as:
Well-formed: If the XML document adheres to all the general XML rules such as tags must be
properly nested, opening and closing tags must be balanced and empty tags must end with '/>', then it
is called as well-formed.
Valid: An XML document said to be valid when it is not only well-formed, but it also conforms to
available XSD that specifies which tags it uses, what attributes those tags can contain and which tags
can occur inside other tags, among other properties.
Limitaions of Document Type Declaration (DTD)
There is no bult-in data type in DTDs
No new data types can be created in DTDs
The use of cardinatlity in DTDs is limited
Namespaces are not supported
DTDs provide very limited support for modularity and reuse
We can not put any restrictions on text content
Defaults for elements can not be specified
We have very little control over mixed content
DTDs are written in strange format and are difficult to validate
Strengths of XML Schema(XSD)
XML schema provided much grater specification than DTDs
They support large number of built-in data types
They support namespaces
They are extensible to future additions
They support uniqueness and referencial integrity constraints in much better way
It is easier to define data restrictions
XSD Structure:
An XML XSD is kept in a separate document and then the document having extension .xsd and is be
linked to the XML document to use it. Schema is the root element of XSD and it is always required.
Syn: <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
…
</xs:schema>
Above fragement specifies that elements and datatypes used in the schema are defined in
"http://www.w3.org/2001/XMLSchema" namespace and these elements/data types should be prefixed with
xs. Similarly, XSD can be linked to xml file with following syntax:
www.Jntufastupdates.com 9
P a g e | 10
XSD Validation:
We'll use Java based XSD validator to validate the bookstore.xml against the books.xsd.
XSDValidator.java
import java.io.*;
import javax.xml.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.*;
import javax.xml.validation.*;
import org.w3c.dom.*;
www.Jntufastupdates.com 10
P a g e | 11
Element declaration:
Elements are primary building blocks in XML document. Element type declaration can be done
using <xs:element> tag with following syntax.
Syn: <xs:element name=”element-name” type=”element-type”>
Ex: <xs:element name=”title” type=”xs:string”>
Each element declaration within the XSD has mandatory attribute name. the value of this name
attribute is the element name attribute is the element name that will appear in the XML document. Element
definition may also have optional type attribute, which provides description of what can be containted within
the element when it appears in XML document. Every XML document must have root element. This root
element must be declared first in schema for conforming XML documents.
Ex: <!xml version=”1.0”?>
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<xs:element name=”bookstore”>
</xs:element>
</xsd:schema>
Declarting simple elements:
Simple type elements can contain only text and/or data. They can not have child elements or
attributes, and can not be empty. Simple elements are defined as follows:
Syn: <xs:element name=”element-name” type=”element-type”>
Ex: <xs:element name=”title” type=”xs:string”/>
The value of type attributes specifies an elements content type and can be any simple type. This
attribute can be any complex type.
Default Value: Simple Element can have default value that specifies the default content to be used
when not content is specified. When an element is declared with default value, the value of the
element is whatever value appears as elements content in instance document. Following example
illustrates this:
<xs:element name="gender" type="xs:boolean" default="true" />
Fixed Value: Simple Element can also have optional fixed value. Fixed attribute is used to ensure
that elements content is always set to particular value. Consider the following syntax:
<xs:element name="branch" type="xs:string" fixed="IT" />
Occurance indicators: an element have two optional attributes : minOccurs and maxOccurs. They
are used to specify the number of times an element can occur in XML document.
o minOccurs: this attribute specifies minimum number of times an element can occur. The
following is example of usage of this attribute:
<xs:element name=”option” type=”xs:string” minOccurs=”0”/>
www.Jntufastupdates.com 11
P a g e | 12
o maxOccurs: this attribute specifies maximum number of times an element can occur. The
declaration of element will be as follows:
<xs:element name=”option” type=”xs:string” maxOccurs=”10”/>
Schema DTD Meaning
minOccurs=’0’, maxOccurs=’unbounded’ * Zero or more
minOccurs=’1’, maxOccurs=’unbounded’ + One or more
Minoccurs=’0’ ? Optional
None None Exactly one
Declarting complex elements:
Complex types can be named or can be anonymous. They are associated with complex elements in
the same manner, typically using a type definition and an element declaration. By default, complex type
elements have complex content i.e. they have child elements. Complex type elements can be limited to
having simple content i.e. they contain only text. General form of element declaration is:
Syn: <xs:complexType name=”complex-type-name”><xs:sequence>
</xs:sequence></xs:complexType>
Ex: <xs:complexType name=”sName”><xs:sequence>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”lase” type=”xs:string”/>
</xs:sequence></xs:complexType>
Atribute declaration:
Attrbibutes are used to describe properties of an element. Attributes themselves are always declared
as simple types as follows:
Syn: <xs:attribute name”attribute-name” type=”attribute-type”>
Ex: <xs:attribute name=”id” type=”xs:string’/>
Simple types can not have attributs. Element that have attributes are complex types. So, attributes
declaration always occurs as part of complex type declaration, immediately after its content model.
Ex: <xs:complexType name=”sName”><xs:sequence>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”lase” type=”xs:string”/>
</xs:sequence>
<xs:attribute name=”id” type=”xs:string”/>
</xs:complexType>
A part from this simple definition, there can be additional specifications for attributes:
Attribute element properties:
o use: possible values are optional, required and prohibited.
<xs:attribute name=”id” type=”xs:string” use=”required”/>
o default: this specifies the value to be used if attribute is not specified
<xs:attribute name=”gender” type=”xs:boolean” default=”false”/>
o fixed: it specifies that attribute, if it appears must always have fixed value specified. If the
attribute does not appear, the schema processor will provide attribute with value specified
here.
<xs:attribute name=”unit” type=”xs:boolean” default=”rpm”/>
Order Indicators
o All: Child elements can occur in any order.
<xs:all>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”last” type=”xs:string”/>
www.Jntufastupdates.com 12
P a g e | 13
</xs:all>
o Choice: Only one of the child element can occur.
<xs:choice>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”last” type=”xs:string”/>
</xs:choice>
o Sequence: Child element can occur only in specified order.
<xs:sequence>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”last” type=”xs:string”/>
</xs:sequence>
Occurence Indicators
o maxOccurs - Child element can occur only maxOccurs number of times.
o minOccurs - Child element must occur minOccurs number of times.
Group Indicators
o Group: a set of related elements can be created using this indicator. the general form for
creating an element group is as follows:
Syn: <xs:group name=”group-name”> … </ xs:group>
Ex: <xs:group name=”personInfo”>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”last” type=”xs:string”/>
</ xs:group>
o attributeGroup: XML Schema provides this element, which is used to group a set of
attributes declarations so that they can be incorporated into complex types definitions with
syntax:
Syn: <xs:attributeGroup name=”group-name”> … </ xs:attributeGroup>
Ex: <xs: attributeGroup name=”personInfo”>
<xs:element name=”first” type=”xs:string”/>
<xs:element name=”middle” type=”xs:string”/>
<xs:element name=”last” type=”xs:string”/>
</ xs: attributeGroup>
Annotations declaration:
XML schema provides three annotation elements for documentation purposes in XML schema
instance. They provide a way to write realistic ans structured comments for the benefit of applications. An
annotation is represented by <annotation> element which typically appears at the beginning of most
schemas. However, it can appear inside any complex element definition. It can contain only two elements
<appinfo> and <documentation> any number of times. Following is an example:
<xs:annotation>
<xs:documentation> <author>Uttam Roy</author></xs:documentation>
<xs:appinfo><version>2.1</version></xs:appinfo>
</xs.annotation>
www.Jntufastupdates.com 13
P a g e | 14
www.Jntufastupdates.com 14
P a g e | 15
The Document Object Model(DOM) is an application programming interface(API) for HTML and
XML documents. It defines the logical structure of documents and the way a document is accesses and
manipulated. DOM is a set of platform independent and language neutral application programming
interface(API) which describes how to access and manipulate the information stored in XML or in HTML
documents. Main objectives of DOM are Accessing the elements of document, deleting the elements of
documents and changing the elements of document.
DOM models document as hierarchical structure consisting of different kinds of nodes. Each of these
nodes represents specific portion of the document. Some kind of nodes may have children of different types.
Some nodes cannot have anything below it in the hierarchical structure and are leaf nodes. With the
Document Object Model, programmers can build documents, navigate their structure, and add, modify, or
delete elements and content. Anything found in an HTML or XML document can be accessed, changed,
deleted, or added using the document object model. The DOM is separated into 3 different parts/levels:
1. Core DOM: This portion defines the basic set of interfaces and objtects for any structured document
2. HTML DOM:
The HTML Document Object Model (DOM) is a programming API for HTML documents. It defines
the logical structure of documents and the way a document is accessed and manipulated. With the Document
Object Model, programmers can create and build documents, navigate their structure, and add, modify, or
delete elements and content. Anything found in an HTML document can be accessed, changed, deleted, or
added using the Document Object Model, with a few exceptions - in particular, the DOM interfaces for the
internal subset and external subset have not yet been specified.
XML DOM:
According to the DOM, everything in an XML document is a Node. The DOM says: The entire
document is a document node, Every XML element is an element node, The text in the XML elements are
text nodes, Every attribute is an attribute node, Comments are comment nodes.
The root node in the XML above is named <bookstore>. All other nodes in the document are
contained within <bookstore>. The root node <bookstore> holds four <book> nodes. The first <book> node
holds four nodes: <title>, <author>, <year>, and <price>, which contains one text node each, "Everyday
Italian", "Giada De Laurentiis", "2005", and "30.00". The XML DOM views an XML document as a tree-
structure. The tree structure is called a node-tree. All nodes can be accessed through the tree. Their contents
can be modified or deleted, and new elements can be created.
The node tree shows the set of nodes, and the connections between them. The tree starts at the root
node and branches out to the text nodes at the lowest level of the tree. The nodes in the node tree have a
hierarchical relationship to each other. The terms parent, child, and sibling are used to describe the
relationships. Parent nodes have children. Children on the same level are called siblings (brothers or sisters).
In a node tree, the top node is called the root, Every node except the root has exactly one parent node.
www.Jntufastupdates.com 24
www.Jntufastupdates.com 41