XML Interview questions are very popular in various programming job interviews, including Java interviews for web developer. XML is a matured technology and often used as standard for transporting data from one platform other. XML Interview questions contains 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 10 frequently asked XML Interview questions and answers from 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 skill in programmer, it make 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 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.
Question 1: What is XML ?
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 mark-up language 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.
Question 3: What is XPath ?
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.
Question 4: What is XSLT?
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 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.
Question 5: What is element and attribute in XML?
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>
In this sample XML id is an attribute of
are also other elements but they don’t have any attribute.
Question 6: What is meaning of well formed XML ?
Answer : Another interesting XML interview question which 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.
Question 7: What is XML namespace? Why it’s important?
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>
Question 8: Difference between DOM and SAX parser ?
Answer : This is another very popular XML interview question, not just in XML world but also on Java world. Main difference between DOM and SAX parser is the way they parse XML documents. DOM creates an in memory tree representation of XML documents during parsing while SAX is a event driven parser. See Difference between DOM and SAX parser for more detailed answer of this question.
Question 9: What is a CDATA section in XML?
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 “]]>”.
Question 10: What is XML data Binding in Java?
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 convenient way to bind XML documents with Java objects. Other alternatives for XML binding is using open source library e.g. XML Beans. One of the biggest advantage 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. Important of XML technologies like XPath, XSLT, XQuery is only going to increase because of platform independent nature of XML and it’s popularity of transmitting data over cross platform. Though XML has disadvantage like verbosity and size but its highly useful in web services and transmitting data from one system to other where bandwidth and speed is of secondary concern.
Other Interview questions articles from Javarevisited Top 30 UNIX and Linux command Interview questions – Answered
- 20 design pattern and software design Interview questions with answers
- 10 Oracle Interview questions with answers
- 15 Java multi-threading Interview questions with answers asked in Investment banks
- Top 10 Java String Interview questions – Answered
Reference: 10 XML Interview questions and answers for Java Programmer from our JCG partner Javin Paul at the Javarevisited blog.