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. 

Define XPATH and what is XSLT?

XPATH is an XML query language to select specific parts of an XML document. Using XPATH we can address or filter elements and text in a XML document. For instance a simple XPATH expression like "book/price" states find "price" node which are children of "Invoice" node. XSLT is a rule based language used to transform XML documents in to other file formats. XSLT are nothing but generic transformation rules which can be applied to transform XML document to HTML, CS, Rich text etc.

What is SOAP and how does it relate to XML?
The Simple Object Access Protocol (SOAP) uses XML to define a protocol for the exchange of information in distributed computing environments. SOAP consists of three components: an envelope, a set of encoding rules, and a convention for representing remote procedure calls. Unless experience with SOAP is a direct requirement for the open position, knowing the specifics of the protocol, or how it can be used in conjunction with HTTP, is not as important as identifying it as a natural application of XML.

Latest Updates

Indian Geography

What is the approximate distance between earth and the moon?

Indian History

In which year was the battle of ‘Koregaon Bhima’ fought?

The approach that is very useful in organizing the content in history is.

General Knowledge of India

NITI Aayog stands for _____.

General Knowledge of MP

India’s first Ramayan art museum was established at?

Errors Identification

Read the sentence carefully and choose the option that has an error in it:
The management’s trusted employee was suspected of stealing large sum of money.

Read the sentence carefully and choose the option that has an error in it:
The teacher asked the child to repeat again because he spoke feebly.

Fill in the blank

Fill in the blank with the most appropriate preposition in the given sentence.
Let’s sit _________ the shade of this beautiful tree.

Choose the most appropriate determiner for the given sentence.
________of what he said was very sensible.

Substitution

Choose the option that substitutes the given phrase appropriately.
A work of art made by carving

Correct sentence

Choose the option that best transforms the sentence into its Indirect form:
‘What country do you come from?’ said the police officer.

Alternative Phrase

Choose the option that best explains the highlighted expression:
All human beings have feet of clay.

Fill in the blank

Choose an appropriate modal for the given sentence:
My doctor said that I_____ stop smoking as one of my lungs got infected.

Choose the appropriate prepositions for the given sentence:
My parents have been married ________ forty-nine years, but you can still see the love ________ their eyes.

Choose the appropriate conjunction for the given sentence:
______ it rains, the college will declare the holiday.

Antonyms

Choose the appropriate antonym for the highlighted word in the given sentence.
The family protracted their visit by several days.

Tenses

Choose the appropriate tenses to fill in the blanks in the given sentence:
Please _________ a noise. Ritu __________ to sleep.

Synonyms

Choose the appropriate synonym for the highlighted word in the given sentence.
Does he really expect us to believe such a flimsy excuse?