XML Interview Questions and Answers

What is XML?
XML stands for extensible markup language much like as a HTML. XML was designed to carry data, not to display data. XML loosely couples disparate applications or systems utilizing JMS, Web services etc. XML uses the same building blocks that HTML does: elements attributes and values. XML tags are not predefined. You must define your own tags.
Why is XML important?

Scalable: Since XML is not in a binary format you can create and edit files with anything and it's also easy to debug. XML can be used to efficiently store small amounts of data like configuration files (web.xml, application.xml, strutsconfig. xml etc) to large company wide data with the help of XML stored in the database. 
Fast Access: XML documents benefit from their hierarchical structure. Hierarchical structures are generally faster to access because you can drill down to the section you are interested in. 
Easy to identify and use: XML not only displays the data but also tells you what kind of data you have. The mark up tags identifies and groups the information so that different information can be identified by different application. 
Style ability: XML is style-free and whenever different styles of output are required the same XML can be used with different style-sheets (XSL) to produce output in XHTML, PDF, TEXT, another XML format etc. 
Linkability, in-line usability, universally accepted standard with free/inexpensive tools

Describe the differences between XML and HTML?

XML HTML
designed to transport and store data, with focus on what data is designed to display data, with focus on how data looks
User definable tags Defined set of tags designed for web display
Content driven Format driven
End tags required for well formed documents End tags not required
Quotes required around attributes values Quotes not required
Slash required in empty tags Slash not required

 

Is XML meant to replace HTML?

No, they both go together one is for describing data while other is for displaying data.

What is CDATA section in XML?

All data is normally parsed in XML but if you want to exclude some elements you will need to put those elements in CDATA.

What is XSL?
XSL (the extensible Style sheet Language) is used to transform XML document to some other document. So its transformation document which can convert XML to some other document. For instance you can apply XSL to XML and convert it to HTML document or probably CSV files.
Is XML case sensitive?
XML tags are case sensitive. The tag is different from the tag .

What is DOM?
A DOM (Document Object Model) defines a standard way for accessing and manipulating documents. The XML DOM defines a standard way for accessing and manipulating XML documents. The XML DOM views an XML document as a tree-structure. All elements can be accessed through the DOM tree. Their content (text and attributes) can be modified or deleted, and new elements can be created. The elements, their text, and their attributes are all known as nodes.
Define DTD (Document Type definition)?
DTD - Document Type Definition defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes. XML DTD is a rule book that an XML document follows. Once DTD is ready, you can create number of XML documents following the same rules specified in the DTD. DTD can be internal or external DTD. The internal DTD is included in the XML document, while external DTD exists outside the content of the documents.
Explain DTD and schema?

A DTD provides a list of the elements, attributes, comments, notes, and entities contained in an XML or HTML document and indicate their relationship with each other. 

DTD supports two types of data - CDATA and PCDATA.
Schema means the organization and the structure of a database. Schema supports numeric, Boolean and String data types and suitable for applications that developed in a programming language. Schema supports custom data types. Schema supports encapsulation and inheritance concepts. Schema supports for WEB services, XSLT.

E.g.: An XML schema is a description of XML document. It is expressed in terms of constraints on the structure and content of documents.

What are the standard ways of parsing XML document? or What is a XML parser?

XML parser sits in between the XML document and the application who want to use the XML document. Parser exposes set of well defined interfaces which can be used by the application for adding, modifying and deleting the XML document contents. 

There are two standard specifications which are very common and should be followed by a XML parser:- 

DOM: - Document Object Model.
IT is an open standard. The XML file is arranged in a tree fashion. DOM supports random access to the data of XML file. 
DOM is a W3C recommended way for treating XML documents. In DOM we load entire XML document into memory and allows us to manipulate the structure and data of XML document. 

SAX: - Simple API for XML. 
SAX is event driven way for processing XML documents. In DOM we load the whole XML document in to memory and then application manipulates the XML document. But this is not always the best way to process large XML documents which have huge data elements. For instance you only want one element from the whole XML document or you only want to see if the XML is proper which means loading the whole XML in memory will be quiet resource intensive. SAX parsers parse the XML document sequentially and emit events like start and end of the document, elements, text content etc. So applications who are interested in processing these events can register implementations of callback interfaces. 
SAX parser then only sends those event messages which the application has demanded. 

In What scenarios will you use a DOM parser and SAX parser?

If we do not need all the data from the XML file then SAX approach is much preferred than DOM as DOM can quiet memory intensive. In short if you need large portion of the XML document its better to have DOM. 
With SAX parser you have to write more code than DOM. 
If we want to write the XML in to a file DOM is the efficient way to do it. 
Some time you only need to validate the XML structure and do not want to retrieve any Data for those instances SAX is the right approach. 

Latest Updates

Trigonometry

What is the value of cot 4π/3 ?

Indian Politics

Article-24 of the Indian Constitution ‘Prohibition of employment of children in factories, etc’ deals with?

Article-134A of the Indian Constitution ‘Certificate for appeal to the Supreme Court’ deals with?

Chemistry

Who invented Aspirin?

Physics

A larger force on a rotating body results in larger?

What is the unit of the physical quantity, magnetic flux density?

Algebra

The system of equations 2x + 4y = 6 and 4x + 8y = 8 is ?

Time and Distance

A thief is spotted by a policeman from a distacne of 100 m. When the policeman starts the chase, the thief also starts running. If the speed of the theif is 8 km / hour and that of the policeman is 10 km/hour, then how far will the theif have to run before he is overtaken?

Algebra

Aman and Alok attempted to solve a quadratic equation. Aman made a mistake in writing down the constant term and ended up in roots (4, 3). Alok made a mistake in writing down the coefficient of x to get roots (3, 2). The correct roots of the equation are?

Compound Interest

The effective annual rate of interest corresponding to a nominal rate of 22% per annum payable half-yearly is?

Volume and Surface Area

If the volume of a cylinder is 2156 cubic cm and height is 14 cm, find its radius?

Algebra

What is the equation of the line which passes through the points (2, 3) and (- 4, 1)?

Triangles

In △ABC, the angle bisector of ∠A cuts BC at E. Find length of AC, if lengths of AB, BE and EC are 9 cm, 3.6 cm and 2.4 cm?

In a triangle, the length of the opposite side of the angle which measures 45° is 8√2 cm, what is the length of the side opposite to the angle which measures 90°?

General Knowledge of India

The boundary line between India and Pakistan is called?

Which city is located on the banks of the river Mahanadi?

Indian History

When was the battle of Haldighati fought?

In 1498, which Portuguese explorer discovered a new sea route from Europe to India?

General Knowledge of India

Chapchar Kut is a festival of which State?

Chemistry

In chemistry, soap is a salt of a ?

Indian Economy

Which of the following is a Direct tax?

Biology

Sauria lacertidae is the scientific name of?

Which of the following is a primary function of haemoglobin?

Average

A factory buys 8 machines.3 Machine A, 2 Machine B and rest Machine C. Prices of the machines are 100000, 80000 and 45000 respectively.Calculate the average cost of these machines?

Discount

Ticket for an adult is 500 and a child is 200. 1 child goes free with two adults. If a group has 20 adults and 8 children what will be the discount the group get?