2014-10-04

Latest XML Interview Questions and Answers:
What is XML?

Extensible Markup Language (XML) is the universal language for data on the Web
XML is a technology which allows us to create our own markup language.
XML documents are universally accepted as a standard way of representing information in platform and language independent manner.
XML is universal standard for information interchange.
XML documents can be created in any language and can be used in any language.

What is the difference between XML and HTML?

XML is no way clashes with HTML, since they are for two different purposes.

HTML

XML

HTML is for displaying purpose.

whereas  XML is for data representation.

HTML is used to mark up text so it can be displayed to users.

XML is used to mark up data so it can be processed by computers.

HTML describes both structure and appearance

XML describes only content, or “meaning”

HTML uses a fixed, unchangeable set of tags

In XML, you make up your own tags

What are the benefits of XML?

There are many benefits of using XML on the Web :

Simplicity- Information coded in XML is easy to read and understand, plus it can be processed easily by computers.

Openness- XML is a W3C standard, endorsed by software industry market leaders.

Extensibility - There is no fixed set of tags. New tags can be created as they are needed.

Self-description- In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes.

Contains machine-readable context information- Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.

Separates content  from presentation- XML tags describe meaning not presentation. The motto of HTML is: "I know how it looks", whereas the motto of XML is: "I know what it means, and you tell me how it should look." The look and feel of an XML document can be controlled by XSL style sheets, allowing the look of a document to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.

Supports multilingual documents and Unicode-This is important for the internationalization of applications.

Facilitates the comparison and aggregation of data - The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.

Can embed multiple data types - XML documents can contain any possible data type - from multimedia data (image, sound, video) to active components (Java applets, ActiveX).

Can embed existing data - Mapping existing data structures like file systems or relational databases to XML is simple. XML supports multiple data formats and can cover all existing data structures and .

Provides a 'one-server view' for distributed data - XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data - the World Wide Web can be seen as one huge XML database.

What is a well-formed XML document?

If a document is syntactically correct it can be called as well-formed XML documents. A well-formed document conforms to XML's basic rules of syntax:

Every open tag must be closed.
The open tag must exactly match the closing tag: XML is case-sensitive.
All elements must be embedded within a single root element.
Child tags must be closed before parent tags.
A well-formed document has correct XML tag syntax, but the elements might be invalid for the specified document type.

What is XML DOM Document?

XML Document object represents the whole XML document, and it is the root of a document tree. It gives access to entire XML document – Nodes and Elements, and it has its own properties.

What is XPath?

XPath is used to find information in an XML document and contains standard functions. XPath is the major element in XSLT, and it is w3c recommendation.

What is an attribute?

An attribute provides more or additional information about an element than otherwise.

Can we have empty XML tags?

Yes, we can have empty tags in XML. Empty tags are used to indicate elements that have no textual content.

What are the advantages of XML DOM Document?

Advantages of XML DOM:

• XML structure is traversable, and it can be randomly accessed by traversing the tree.

• XML structure is modifiable, and values can be added, changed and removed

What are the basic rules while writing XML?

These are the basic rules while writing XML:

All XML should have a root element

All tags should be closed

XML tags are case sensitive

All tags should be nested properly

Tag names cannot contain spaces

Attribute value should appear within quotes

White space is preserved

What is XML Element?

An XML document contains XML Elements, and it starts from an element’s start tag to end tag. It can contain:

Other elements within main element

An Attribute

text

What is a valid XML document?

If a document is structurally correct then it can be called as valid XML documents. A valid document conforms to the predefined rules of a specific type of document:

These rules can be written by the author of the XML document or by someone else.
The rules determine the type of data that each part of a document can contain.
Note:Valid XML document is implicitly well-formed, but well-formed may not be valid

What is CDATA?

CDATA is unparsed character data that cannot be parsed by the XML parser. Character < and > are illegal in XML elements. CDATA section starts with <![CDATA[“ and end with “]]>”.

How comment can be represented in XML?

Comment can be represented as <!- – comments – -> as like HTML. This comment symbol is applicable for single or multiple lines.

What are XML Namespaces?

XML namespaces are used to avoid element name conflicts, and it can be avoided by using prefix before the name.

Who is responsible for XML?

XML is a recommendation of the W3C – World Wide Web Consortium and the development are supervised by XML working group.

What is an XML Schema?

An XML schema gives the definition of an XML document, and it has following:

• Elements and attributes

• Elements that are child elements

• Order of child elements

• Data types of elements and attributes

What is well formed XML document?

A well-formed XML document must follow the following rules  –

• Every start tag should end with an end tag

• XML tags are case sensitive

• Empty tags are necessary to close with a forward slash

• All tags should be properly nested

Why XML has been used for development?

XML is used for development for following reasons:

Used for Database driven websites

Used to store data for e-commerce websites

Used to transport and store data on internet

XML is used for database and flat files

Generate dynamic content by applying different style sheets

What is SGML?

SGML is large and powerful Standard Generalized markup Language which is used to define descriptions of the structure of different types of electronic document.

Can I execute a XML?

No, we cannot execute XML, and it is not a programming language to execute. It is just a markup language to represent the data.

What are the special characters used in XML?

<, > and & are the special characters used in XML. Because these characters are used for making tags.

What is a Processing Instruction in XML?

A Processing Intruction is the information which we would like to give to application. Through a Processing Instruction an application would get idea about how to process the document. A Processing Instruction can appear anywhere and any no. of times in a document.

How does the XML structure is defined?

XML document will have a structure which has to be defined before we can create the documents and work with them. The structural rules can be defined using many available technologies, but the following are popular way of doing so-

Document Type Definition (DTD)

Schema

What is DTD?

A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines rules for a specific type of document, including:

Names of elements, and how and where they can be used
The order of elements
Proper nesting and containment of elements
Element attributes
To apply a DTD to an XML document, you can:

Include the DTD's element definitions within the XML document itself.
Provide the DTD as a separate file, whose name you reference in the XML document.

What are differences between DTDs and Schema?

Schema

DTD

Schema document is an XML document i.e., the structure of an XML document is specified by another XML document.

DTDs follow SGML syntax.

Schema supports variety of dataTypes similar to programming language.

In DTD everything is treated as text.

In Schema,  It is possible to inherit and create relationship among elements.

This is not possible in DTD without invalidating existing documents.

In Schema, It is possible to group elements and attributes so that they can be treated as single logical unit.

Grouping of elements and attributes is not possible in DTD.

In Schemas, it is possible to specify an upper limit for the number of occurrences of an element

It is not possible to specify an upper limit of an element in DTDs

What is a Complex Element?

A complex element is an XML element that contains other elements and/or attributes.

There are four kinds of complex elements:

empty elements

elements that contain only other elements

elements that contain only text

elements that contain both other elements and text

What is a Simple Element?

A simple element is an XML element that can contain only text.

A simple element cannot have attributes

A simple element cannot contain other elements

A simple element cannot be empty

However, the text can be of many different types, and may have various restrictions applied to it.

What are namespaces? Why are they important?

A simple element is an XML element that can contain only text. Namespaces are a simple and straightforward way to distinguish names used in XML documents, no matter where they come from. XML namespaces are used for providing uniquely named elements and attributes in an XML instance They allow developers to qualify uniquely the element names and relationships and make these names recognizable, to avoid name collisions on elements that have the same name but are defined in different vocabularies.
They allow tags from multiple namespaces to be mixed, which is essential if data is coming from multiple sources.

What is XML parser?

An XML parser is a piece of software which can do following:

Check for well-formedness
Validate the document
Allows us to read, create or modify existing XML documents

What is SAX?

SAX-Simple API for XML processing. SAX provides a mechanism for reading data from an XML document. It is a popular alternative to the Document Object Model (DOM).SAX provides an event based processing approach unlike DOM which is tree based.

What are the interfaces of SAX?

The interfaces of SAX are:

DocumentHandler- is used for getting event notification relating to a document.
DTDHandler- is implemented to get the notifications related to declarations in DTD like entities and notations
EntityResolver- is used for reading external entities.
ErrorHandler- is used for handling error related notifications.

What is XSL?

eXtensible Stylesheet Language(XSL)  deals with most displaying the contents of XML documents.XSL consists of three parts:

XSLT - a language for transforming XML documents
XPath - a language for navigating in XML documents
XSL-FO - a language for formatting XML documents

Show more