XML Interview Questions

1. What is XML?

[Ans]XML is a very handy format for storing and communicating your data between disparate systems in a platform-independent fashion.

2. What is the difference between XML schema and DTD?

[Ans]The DTD provides a basic grammar for defining an XML Document in terms of the metadata that comprise the shape of the document. An XML Schema provides this, plus a detailed way to define what the data can and cannot contain. It provides far more control for the developer over what is legal, and it provides an Object Oriented approach, with all the benefits this entails.

So, if XML Schemas provide an Object Oriented approach to defining an XML document's structure, and if XML Schemas give us the power to define re-useable types such as an ISBN number based on a wide range of pre-defined types, why would we use a DTD? There are in fact several good reasons for using the DTD instead of the schema.

Firstly, and rather an important point, is that XML Schema is a new technology. This means that whilst some XML Parsers support it fully, many still don't. If you use XML to communicate with a legacy system, perhaps it won't support the XML Schema.

Many systems interfaces are already defined as a DTD. They are mature definitions, rich and complex. The effort in re-writing the definition may not be worthwhile.

DTD is also established, and examples of common objects defined in a DTD abound on the Internet -- freely available for re-use. A developer may be able to use these to define a DTD more quickly than they would be able to accomplish a complete re-development of the core elements as a new schema.

Finally, you must also consider the fact that the XML Schema is an XML document. It has an XML Namespace to refer to, and an XML DTD to define it. This is all overhead. When a parser examines the document, it may have to link this all in, interperate the DTD for the Schema, load the namespace, and validate the schema, etc., all before it can parse the actual XML document in question. If you're using XML as a protocol between two systems that are in heavy use, and need a quick response, then this overhead may seriously degrade performance.

Then again, if your system is available for third party developers as a Web service, then the detailed enforcement of the XML Schema may protect your application a lot more effectively from malicious -- or just plain bad -- XML packets. As an example, Muse.net is an interesting technology. They have a publicly-available SOAP API defined with an XML Schema that provides their developers more control over what they receive from the user community.

3. What is the difference between SAX and DOM?

[Ans]DOM uses the principle of reading the entire XML document into memory. SAX, however, is more like an event parsing mechanism because it fires or triggers events depending on where it is in the course of parsing the document.

The tree-based W3C DOM parser creates an internal tree based on the hierarchical structure of the XML data. You can navigate and manipulate this tree from your software, and it stays in memory until you release it. DOM uses functions that return parent and child nodes, giving you full access to the XML data and providing the ability to interrogate and manipulate these nodes. DOM manipulation is straightforward and the API does not take long to understand, particularly if you have some JavaScript DOM experience.

Because DOM stores the entire document as a memory map, it is not resource friendly.

SAX, on the other hand, creates no such memory map and hence has a smaller memory "footprint." The SAX specification defines an event-based approach whereby parsers scan through XML data, calling handler functions whenever certain parts of the document (e.g., text nodes or processing instructions) are found.

4. Describe the differences between XML and HTML?

[Ans]
XML HTML

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

5. Describe the role that XSL can play when dynamically generating HTML pages from a relational database?

[Ans]It is used for Querying a database and then formatting the result set so that it can be validated as an XML document allows developers to translate the data into an HTML table using XSLT rules. Consequently, the format of the resulting HTML table can be modified without changing the database query or application code since the document rendering logic is isolated to the XSLT rules.

6. What is DOM and how is it related to XML?

[Ans]The Document Object Model (DOM) is a maintained by the W3C DOM Workgroup and defines an application independent mechanism to access, parse, or update XML data. In simple terms it is a hierarchical model that allows developers to manipulate XML documents easily.

7. What is SOAP and how does it relate to XML?

[Ans]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.

8. Can you walk us through the steps necessary to parse XML documents?

[Ans]Choose between a non-validating parser and a validating parser depending upon the requirements. Then decide wether to go for SAX or DOM and parse the same. We should also consider handling any issues with the XML file

9. Give some examples of XML DTDs or schemas that you have worked with.

[Ans]Although XML does not require data to be validated against a DTD, many of the benefits of using the technology are derived from being able to validate XML documents against business or technical architecture rules. Polling for the list of DTDs that developers have worked with provides insight to their general exposure to the technology. The ideal candidate will have knowledge of several of the commonly used DTDs such as FpML, DocBook, HRML, and RDF, as well as experience designing a custom DTD for a particular project where no standard existed.

Join javaquestions Group
Google
Email your answers to Java Interview Questions

The Advertising Network

Disclaimers: No claims are made about the accuracy of any of the document presented in this site and no responsibility is taken for any errors. All the links provided in this site are individual compilation, however no claims are made about the accuracy and authenticity of the respective contents(including java interview questions).