XML Interview questions are very popular in various programming job
interviews, including Java interviews for web developers.
XML is a mature technology and is often used as a standard for transporting data
from one platform to another. XML Interview
questions contain questions from various XML technologies like XSLT which
is used to transform XML files, XPATH, XQuery, and fundamentals
of XML e.g. DTD or Schema. In this article, we will see the top 10 frequently asked XML Interview questions and answers from the above topics. These questions are mostly asked in various Java interviews but they are equally useful in other programming interviews like C, C++, Scala, or any other programming language.
Since XML is not tied with any programming language and like SQL its one of the desired skills in the programmer, it makes sense to practice some XML questions before appearing in any technical job interview
XML Interview Questions and Answers
Here is my list of some common and frequently asked Interview questions
on XML technologies. Questions on this the list is not very tough but touches some important areas of XML technologies
e.g. DTD, XML Schema, XSLT transformations, XPATH evaluation, XML binding,
XML parsers and fundamentals of XML e.g. namespace, validation, attribute,
elements etc.
Answer: XML stands for Extensible Markup language which means you can
extend XML based upon your needs. You can define custom tags like <books>, <orders>, etc in XML
easily as opposed to other markup languages like HTML where you need to work
with predefined tags e.g. <p> and you can not use user defined
tag.
Though structure of XML can be standardize by making use of DTD and XML
Schema. XML is mostly used to transfer data from one system to another e.g.
between client and server in enterprise applications.
Question 2: Difference between DTD and XML Schema?
Answer : There are couple of differences between DTD and XML Schema e.g.
DTD is not written using XML while XML schema are xml documents in itself,
which means existing XML tools like XML parsers can be used to
work with XML schema.
Also XML schema is designed after DTD and it offer more
types to map different types of data in XML documents. On the other hand DTD
stands for Document Type definition and was a legacy way to define structure of
XML documents.
Answer : XPath is an XML technology which is used to retrieve element
from XML documents. Since XML documents are structured, XPath expression can be
used to locate and retrieve elements, attributes or value from XML files. XPath
is similar to SQL in terms of retrieving data from XML but it has it's own
syntax and rules. See here to know more about How to use XPath to retrieve data from
XML documents.
Answer: XSLT is another popular XML technology to transform one XML file
to other XML, HTML or any other format. XSLT is like a language which specifies
its own syntax, functions and operator to transform XML documents. Usually
transformation is done by XSLT Engine which reads instruction written using
XSLT syntax in XML style sheets or XSL files.
XSLT also makes extensive use of recursion to perform the transformation. One of the popular example of using XSLT is for displaying data
present in XML files as HTML pages. XSLT is also very handy to transforming one
XML file into another XML document.
Answer : This can be best explained by an example. let's see a simple XML
snippet
<Orders>
<Order id="123">
<Symbol> 6758.T</Symbol>
<Price> 2300</Price>
<Order>
<Orders>
<Order id="123">
<Symbol> 6758.T</Symbol>
<Price> 2300</Price>
<Order>
<Orders>
In this sample XML id is an attribute of <Order> element.
Here <Symbol>, <Price> and <Orders> are also
other elements but they don't have any attribute.
Answer: Another interesting XML
interview question that most appeared in telephonic interviews. A well
formed XML means an XML document which is syntactically correct e.g. it
has a root element, all open tags are closed properly, attributes are in quotes
etc. If an XML is not well formed, it
may not be processed and parsed correctly by various XML parsers.
Answer : XML namespace are similar to package in Java and used to
provide a way to avoid conflict between two xml tags of same name but different
sources. XML namespace is defined using xmlns attribute at top of the XML
document and has following syntax
xmlns:prefix="URI". later that prefix is used along with
actual tag in XML documents. Here is an example of using XML namespace :
<root xmlns:inst="http://instruments.com/inst"
<inst:phone>
<inst:number>837363223</inst:number>
</inst:phone>
</root>
<inst:phone>
<inst:number>837363223</inst:number>
</inst:phone>
</root>
Answer: This is another very popular XML interview question, not just in
XML world but also on Java world. The main difference between DOM and SAX parsers is
the way they parse XML documents. DOM creates an in-memory tree representation
of XML documents during parsing while SAX is an event-driven parser. See the Difference between DOM and SAX parser
for a more detailed answer to this question.
Answer : I like this XML Interview questions for its simplicity and
importance, yet many programmer doesn't know much about it. CDATA stands for character
data and has special instruction for XML parsers. Since XML parser parse all
text in XML document e.g. <name>This is name of person</name> here even though value of tag <name> will be
parsed because it may contain XML tags e.g. <name><firstname>First
Name</firstname></name>. CDATA
section is not parsed by XML parser. CDATA section starts with "<![CDATA[" and
finishes with "]]>".
Answer: XML binding in Java refers to creating Java classes and object
from XML documents and then modifying XML documents using
Java programming language. JAXB, Java API for XML binding provides a convenient
way to bind XML documents with Java objects.
Another alternative for XML binding
is using an open-source library e.g. XML Beans. One of the biggest advantages of
XML binding in Java is to leverage Java programming capability to create and
modify XML documents.
This list of XML Interview questions and answers are collected
from programmers but useful to anyone who is working in XML technologies. The importance of XML technologies like XPath, XSLT, XQuery is only
going to increase because of the platform-independent nature of XML and its popularity in transmitting data over cross platforms.
Though XML has
disadvantage like verbosity and size but its highly useful in web services and
transmitting data from one system to another where bandwidth and speed is of
secondary concern.
I would add couple of more XML questions into this list :
ReplyDeleteWhat is difference between XQuery and XPath in XML?
Real examples of XPath like how do you get certain elements, list of elements, attributes etc.
One of the XML question asked to me was difference between JSON and XML as data transfer format? Which one is better JSON or XML ?
ReplyDeletedepends Duke, for web services JSON is pretty big now bcause its not as verbose or inflated as XML. I think evelopers still prefer XML, even though some big players like Amazon are moving their APIs to JSON.
ReplyDeleteThe example in question5 is not well formed...
ReplyDeleteA well formed XML document is syntactically correct, so if display data say for a library book issued in the last 2 years, I just display the x # of times the book was issued or display something like this
ReplyDelete<
book_issued> =< 2 years
Can you please let me know answer of question what is difference between a valid and well-formed xml?
ReplyDelete