List out blocks of XML document and explain

XML Basics

XML Syntax

XML syntax is very simple.

All XML documents must have a root element. This is the first element in the document, and it must contain all the other elements:

An XML element is everything from (including) the element’s start tag to (including) the element’s end tag:

An XML attribute has the format name=”value”:

XML Elements

XML elements are the basis for all XML documents. Elements can contain text, other elements, and attributes. All elements must have a start and an end tag. The end tag is optional for empty elements. XML documents must have one and only one root element (also called the document element). Examples of common XML elements include:

-start tag
-end tag
-empty element
-root element

XML Attributes

In addition to elements, XML documents often contain attributes. An attribute is a bit of information that is attached to an element. Just as an element can have multiple child elements, it can also have multiple attributes.

Attributes always have a name and a value, but the value does not have to be enclosed in quotes. When an attribute value does contain spaces, it must be enclosed in quotes. Single or double quotes can be used, but they must match.

The value of an attribute cannot contain line breaks, so if you need to use a long value, you will need to use an entity reference or CDATA section.

Here is an example of an XML element with two attributes:

Pride and Prejudice Jane Austen 24.95

XML Document Structure

XML Declaration

An XML declaration comes at the very beginning of an XML document, and it is optional. If it exists, it must come first, before anything else, including the document type declaration.
The XML declaration has the following syntax:

The version attribute is mandatory, but the encoding attribute is optional. The encoding attribute specifies the character encoding used in the document. If this attribute is not specified, then UTF-8 is assumed.

XML Comments

XML comments start with .

All text between these two symbols will be ignored by the XML parser.

An XML comment can be placed anywhere in an XML document.

XML Processing Instructions

An XML processing instruction (PI) is a markup construct that’s used to pass information to applications that process XML documents. In essence, a PI is an XML version of a command line. A PI consists of two parts:

  • A target element, which identifies the application to which the instruction is directed.
  • Processing data, which provides information or instructions for the application identified by the target element.

The most common use of PIs is to identify the type of software used to generate or process an XML document. For example, many XML editors use PIs to identify themselves as the source of a document. Other common uses for PIs include declaring character encodings and providing conditional processing instructions (such as “ifThenElse” statements).

XML Namespaces

As in HTML, an XML document has both a head and a body. The head includes information about the document, while the body contains the actual content. In XML, this is accomplished using tags. Tags are the basic markup elements in an XML document.

XML Namespace Declaration

XML namespaces are used for providing uniquely named elements and attributes in an XML document.

An XML namespace is declared using the xmlns attribute. The xmlns attribute can be applied to different elements in the XML document.

When the xmlns attribute is applied to an element, all the element’s children inherit the namespace.

The value of the xmlns attribute is a URI reference that identifies the namespace.

A namespace can be declared with a default namespace or with a prefix.

XML Namespace Scope

An XML namespace can be declared in three different scope levels:


A default namespace is declared without an explicitly given prefix, and all unprefixed elements in the XML document will belong to this namespace. This is often used together with a namespace prefix, to distinguish between elements that belong to the default namespace and elements that belong to a different namespace.

A local namespace declaration applies only to the element where it is declared, and to all child elements of that element. The local declaration overrides any corresponding declarations at a higher scope level, but does not override declarations at the same or lower level. This means that if two local declarations of the same prefix are made, both will be in effect within their respective scopes. However, if a default namespace is declared locally, it will replace any previous declarations of a default namespace at higher levels, including any inherited declarations.

A global namespace declaration applies to the entire document, including any external resources imported into the document. A global declaration overrides any corresponding declarations at lower levels, but does not override local declarations.

XML Schema

XML Schema is an XML-based system for defining the structure, content, and semantics of XML documents. XML Schema provides a means for defining the characteristics of an XML document, including the document’s element and attribute types, content models, and relationships between elements. XML Schema is widely used in the XML community as a means of defining document types.

XML Schema Definition

XML Schema is a language for describing XML documents. It is a W3C Recommendation. An XML Schema describes the structure of an XML document. The elements in an XML document form a document tree. The purpose of an XML Schema is to define the legal building blocks of an XML document:

-The elements and attributes that can appear in a document
-The order in which they must appear
-The number of times they can appear
-The data types of the values allowed for each element or attribute

XML Schema Elements

XML Schema elements can be declared in one of two places:

  • within the element
  • within a parent element

If you want your XML Schema elements to be globally available to any element in your XML document, declare them within the element.

XML Schema Attributes

Attributes are declared in XML schemas using the element. The following example shows how to declare an attribute called “att1” that can take any string value:

The type of an attribute can be any simple type, including built-in types such as xs:string and xs:integer, or user-defined types. Attributes cannot take complex types.

If you don’t specify a type for an attribute, it defaults to xs:string.

You can specify that an attribute is required by using the use=”required” attribute, as follows:

You can also specify a default value for an attribute using the default attribute, as follows:

XML Parsers

XML Parser Libraries

There are a few different libraries that you can use to parse XML documents. Some of the most popular ones include:

-The xml2 library: This library is part of the libxml2 project and is written in C. It can be used to parse XML documents from C or C++ programs.
-The expat library: This library is written in C and was created by James Clark. It can be used to parse XML documents from C programs.
-The libxml++ library: This library is a C++ wrapper around the libxml2 library. It can be used to parse XML documents from C++ programs.
-The Xerces-C++ library: This library is part of the Apache Xerces project and is written in C++. It can be used to parse XML documents from C++ programs.

XML Parser Implementation

There are many XML parsers available for different programming languages. Some of the more common ones are:

  • expat: Written in C, this is a very speedy parser. It is available for a variety of different languages including PHP, Perl, and Python.
  • libxml2: This is the XML parser that comes with the GNOME project. It is written in C and can be used in a variety of different languages as well.
  • Xerces-C++: This is another XML parser written in C++. Apache offers support for Xerces-C++ and it can be used in many different programming languages.

Each of these parsers has its own advantages and disadvantages. You will need to choose the one that best fits your needs based on the language you are using and the features you require.

XML Security

XML Encryption

XML Encryption is the process of applying encryption to data within an XML document. It is a method of providing security for XML data at rest or in transit. By encrypting the data, it becomes unreadable to anyone who does not have the proper key to decrypt it. The process of XML Encryption is divided into two parts:

  1. Encryption of the XML data
  2. Encryption of the XML encryption key

The first step is to encrypt the XML data using a symmetric or asymmetric key. The second step is to encrypt the encryption key itself using a different key, known as a Key Encryption Key (KEK). The KEK can be either symmetric or asymmetric. Once the data and encryption key are encrypted, they can be decrypted by anyone who has the KEK.

XML Encryption is a relatively new technology, and there are still a few wrinkles that need to be ironed out. For example, there is no standard format for encrypting XML data, so each vendor has its own proprietary format. This can make it difficult to exchange encrypted data between different systems. In addition, XML Encryption can be slow and resource-intensive, so it may not be suitable for all applications.

XML Signature

XML Signature is a standard for digital signatures in XML documents. It allows the signer to include extra information about the content being signed, and supports multiple algorithms for signing.

Leave a Reply

Your email address will not be published. Required fields are marked *