Categories
  Frequently Asked Questions
  Jobseeker
XML: Interview Questions
By DearJob.org
 
Share
 
Q1. What is XML?
  • Extensible Markup Language (XML) is the universal language for data on the Web
  • XML is a technology which allows us to create our own markup language.
  • XML documents are universally accepted as a standard way of representing information in platform and language independent manner.
  • XML is universal standard for information interchange.
  • XML documents can be created in any language and can be used in any language.

Q2. What is the difference between XML and HTML?
XML is no way clashes with HTML, since they are for two different purposes. 

HTML

XML

HTML is for displaying purpose.

Whereas XML is for data representation.

HTML is used to mark up text so it can be displayed to users.

XML is used to mark up data so it can be processed by computers.

HTML describes both structure (e.g.

,, ) and appearance (e.g. , , )

XML describes only content, or “meaning”

HTML uses a fixed, unchangeable set of tags

In XML, you make up your own tags


Q3. What are the benefits of XML?
There are many benefits of using XML on the Web:
  • Simplicity- Information coded in XML is easy to read and understand, plus it can be processed easily by computers.
  • Openness- XML is a W3C standard, endorsed by software industry market leaders.
  • Extensibility - There is no fixed set of tags. New tags can be created as they are needed.
  • Self-description- In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes.
  • Contains machine-readable context information- Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.
  • Separates content from presentation- XML tags describe meaning not presentation. The motto of HTML is: "I know how it looks", whereas the motto of XML is: "I know what it means, and you tell me how it should look." The look and feel of an XML document can be controlled by XSL style sheets, allowing the look of a document to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.
  • Supports multilingual documents and Unicode-This is important for the internationalization of applications.
  • Facilitates the comparison and aggregation of data - The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.
  • Can embed multiple data types - XML documents can contain any possible data type - from multimedia data (image, sound, and video) to active components (Java applets, ActiveX).
  • Can embed existing data - Mapping existing data structures like file systems or relational databases to XML are simple. XML supports multiple data formats and can cover all existing data structures and.
  • Provides a 'one-server view' for distributed data - XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data - the World Wide Web can be seen as one huge XML database.
Q4. What is a well-formed XML document?
If a document is syntactically correct it can be called as well-formed XML documents. A well-formed document conforms to XML's basic rules of syntax:
  • Every open tag must be closed.
  • The open tag must exactly match the closing tag: XML is case-sensitive.
  • All elements must be embedded within a single root element.
  • Child tags must be closed before parent tags.
  • A well-formed document has correct XML tag syntax, but the elements might be invalid for the specified document type.

Q5. What is a valid XML document?
If a document is structurally correct then it can be called as valid XML documents. A valid document conforms to the predefined rules of a specific type of document:
  • These rules can be written by the author of the XML document or by someone else.
  • The rules determine the type of data that each part of a document can contain.
Note: Valid XML document is implicitly well-formed, but well-formed may not be valid

Q6. In What scenarios will you use a DOM parser and SAX parser?
Ans: 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 it’s 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.

Q7. What is a Processing Instruction in XML?
A ProcessingIntruction is the information which we would like to give to application. Through a ProcessingInstruction an application would get idea about how to process the document. A ProcessingInstruction can appear anywhere and any no. of times in a document.

Q8. How does the XML structure is defined?
XML document will have a structure which has to be defined before we can create the documents and work with them. The structural rules can be defined using many available technologies, but the following are popular way of doing so-
  • Document Type Definition (DTD)
  • Schema

Q9. What is DTD?
Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines rules for a specific type of document, including:
  • Names of elements, and how and where they can be used
  • The order of elements
  • Proper nesting and containment of elements
  • Element attributes
To apply a DTD to an XML document, you can:
  • Include the DTD's element definitions within the XML document itself.
  • Provide the DTD as a separate file, whose name you reference in the XML document.

Q10. What is XML Schema?
An XML Schema describes the structure of an XML instance document by defining what each element must or may contain.XML Schema is expressed in the form of a separate XML file.
  • XML Schema provides much more control on element and attribute datatypes.
  • Some datatypes are predefined and new ones can be created.    
          
Q11. What are differences between DTDs and Schema?

Schema

DTD

Schema document is an XML document i.e., the structure of an XML document is specified by another XML document.

DTDs follow SGML syntax.

Schema supports variety of dataTypes similar to programming language.

In DTD everything is treated as text.

In Schema, It is possible to inherit and create relationship among elements.

This is not possible in DTD without invalidating existing documents.

In Schema, It is possible to group elements and attributes so that they can be treated as single logical unit.

Grouping of elements and attributes is not possible in DTD.

In Schemas, it is possible to specify an upper limit for the number of occurrences of an element

It is not possible to specify an upper limit of an element in DTDs

 
Q12. What is a Complex Element?
A complex element is an XML element that contains other elements and/or attributes.
There are four kinds of complex elements:
  • empty elements
  • elements that contain only other elements
  • elements that contain only text
  • elements that contain both other elements and text

Q13. What is a Simple Element?
A simple element is an XML element that can contain only text.
  • A simple element cannot have attributes
  • A simple element cannot contain other elements
  • A simple element cannot be empty
  • However, the text can be of many different types, and may have various restrictions applied to it
 
Q14. What are namespaces? Why are they important?
A simple element is an XML element that can contain only text.
  • Namespaces are a simple and straightforward way to distinguish names used in XML documents, no matter where they come from.
  • XML namespaces are used for providing uniquely named elements and attributes in an XML instance
  • They allow developers to qualify uniquely the element names and relationships and make these names recognizable, to avoid name collisions on elements that have the same name but are defined in different vocabularies.
  • They allow tags from multiple namespaces to be mixed, which is essential if data is coming from multiple sources.
Example: a bookstore may define thetag to mean the title of a book, contained only within the element. A directory of people, however, might defineto indicate a person's position, for instance:President. Namespaces help define this distinction clearly. Note: a) Every namespace has a unique name which is a string. To maintain the uniqueness among namespaces an IRL is most preferred approach, since URLs are unique.
  1.       b) Except for no-namespace Schemas, every XML Schema uses at least two namespaces:
    the target namespace.
                    2. The XMLSchema namespace (http://w3.org/2001/XMLSchema)          

Q15. What are the ways to use namespaces?
There are two ways to use namespaces:
  • Declare a default namespace
  • Associate a prefix with a namespace, then use the prefix in the XML to refer to the namespace
Q16. Difference between DTD and XML Schema?
Answer: There are couples 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.
 
Q17. 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 its own syntax and rules.
 
Q18. 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 examples 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.
 
Q19. What is element and attribute in XML?
Answer: This can be best explained by an example. Let’s see a simple XML snippet
 

   id="123">
      6758.T
      2300
  
 
In this sample XML id is an attribute of  element. Here ,  and  are also other elements but they don't have any attribute.
 
Q20. 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.
 
Q21. 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:
 
 xmlns:inst="http://instruments.com/inst"
  
      837363223
   
 
Q22. 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 an event driven parser.
 
Q23. 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. This is name of person  here even though value of tag  will be parsed because it may contain XML tags e.g. First Name. CDATA section is not parsed by XML parser. CDATA section starts with "".
 
Q24. 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 advantages of XML binding in Java is to leverage Java programming capability to create and modify XML documents.

Q25. What is Extensible Markup Language (XML).
XML is a simple and flexible markup language in the text format. Nowadays, it is widely used to exchange a large variety of data over the Internet. XML consists of data as text in well-defined customized layouts by using self-defining tags. These user-defined tags are user friendly because they contain the name given by the user and make the information easily understandable to a user. These user-friendly features made XML to be widely used as a standard data-interchange format. The World Wide Web Consortium (W3C) frequently develops new standard for XML usage by different software vendors and solution providers. XML plays a very significant role with respect to .NET Framework 4.0. .NET Framework 4.0 provides us with a namespace called System.Xml, which includes classes that are used to work with XML.
 
Q26. What is the version information in XML?
“Version” tag shows which version of XML is used.
 
Q27. If XML does not have closing tag will it work?
No, every tag in XML, which is opened, should have a closing tag.
 
Q28. Is XML case sensitive?
Yes, XML is case sensitive.
 
Q29. Explain the difference between XML and HTML.
XML describes data while HTML describes how the data should be displayed. Therefore, HTML is about displaying information while XML is about describing information.
XML supports user-defined tags while HTML provides pre-defined tags.
XML is a case-sensitive language while HTML language is not case-sensitive.
In XML, all tags must be closed; while in HTML, it is not necessary to close each tag.
 
Q30. What is XML DOM?
The DOM stands for Document Object Model, which describes the logical formation of documents and provides the way to access and manipulate a document. It supplies an Application Programming Interface (API) to XML documents. It is built around the object-oriented design; therefore, it is known as DOM. The DOM model considers an XML document as a composition of objects and every object consists of properties and behaviors that can be manipulated by the DOM methods. The DOM allows creating and building XML documents, navigating the structure of documents, and managing the elements and their data. You can use the DOM methods and objects with any language, such as C#, VB, JavaScript, and VBScript.
 
Q31: Define XPATH? And what is XSLT?
Ans: 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.
             
Q32: What is the concept of XPOINTER?
Ans: XPOINTER is used to locate data within XML document. XPOINTER can point to a particular portion of a XML document, for instance
address.xml#xpointer(/descendant::streetnumber[@id=9])
So the above XPOINTER points streetnumber=9 in "address.xml".
 
Q33: What is a valid XML?
Ans: If XML is confirming to DTD rules then it’s a valid XML.
             
Q34: What is CDATA section in XML?
Ans: All data is normally parsed in XML but if you want to exclude some elements you will need to put those elements in CDATA.
             
Q35: What is element and attributes in XML?
Ans: In the below example book is the element and the price the attribute < book price=1002>< /book>
             
Q36: What is XSL?
Ans: XSL (the eXtensible Stylesheet 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.
             
Q37: What are the standard ways of parsing XML document? Or what is a XML parser?
Ans: 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. Now whatever interfaces XML parser exposes should be standard or else that would lead to different vendors preparing their own custom way of interacting with XML document.
There are two standard specifications which are very common and should be followed by a XML parser:-
DOM: - Document Object Model.
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.