XML Question and Answer


1. 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.

2. What is the version information in XML?

“Version” tag shows which version of XML is used.

3. If XML does not have closing tag will it work?

No, every tag in XML, which is opened, should have a closing tag.

4. Is XML case sensitive?

Yes, XML is case sensitive.

5. 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.

6. 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.

7. Which namespaces in .NET are used for XML?

The System.xml.dll is the real physical file, which contains the XML implementation. Some of the other namespaces that allow .NET to use XML are as follows:

  • System.Xml
  • System.Xml.Schema
  • System.Xml.XPath
  • System.Xml.Xsl

8. Explain different types of XML Application Programming Interface (API).

The following are two main types of XML parsers:

  • Tree-based API – Compiles an XML document into a tree structure and loads it into memory. You can traverse and change the tree structure. The DOM is an example of a tree-based API.
  • Event-based API – Provides the report to an application about the parsing events by a set of built-in callback functions. An example of the event-based API is SAX.

9. Explain the XmlReader class.

The XmlReader class is used to read XML data in a fast, forward-only, and non-cached manner.
To work with XmlReader class in .NET, you need to import the following namespace:

In C#:
using System.Xml;

In VB:
Imports System.Xml

10. Describe the XmlWriter class.

The XmlWriter class is used to write XML to a stream, a file, or a Textwriter object. This class works in a forward-only, non-cached manner. You can configure the XmlWriter object up to a large extent. With this object, you can specify a few things, such as whether to indent content or not, the amount to indent, what quote character to use in attribute values, and whether or not namespaces are supported.

11. What is XPath?

XPath stands for XML Path. It is a language used to access different parts of an XML document, such as elements and attributes.

12. What is an XML attribute?

An XML attribute contains additional information regarding that particular element. The XML attributes use the name-value pair. For example, the element student has an attribute called id and the value of this attribute is set to s01, as shown in the following code snippet:

<Student ID=”s01″>


13. The XML elements cannot be empty. Is it true?

No, it is not true.

14. Describe the role that XSL can play while dynamically generating HTML pages from a relational database.

The SQLXML 3.0 and advanced versions provide the facility of mapping the SQL queries output with XSLT templates. It uses XSLT to present the records that are retrieved from databases on Web pages (HTML pages).

An application can use XSLT to modify the output that is retrieved from data sources and display the output by XSL templates. The XSLT displays data without affecting the database query and the code of application.

15. What are the advantages of DOM?

The following are the advantages of DOM:

  • DOM stores the entire XML document into memory before processing. Therefore, the XML structure can be easily modified and values can be added, changed, and removed.
  • DOM enables to traverse the XML structure in any direction. It means that you can access any node of the XML structure by traversing through the XML structure.

16. Give an example of a DOM-enabled XML parser.

The XML parser is MSXML, which is fully DOM-enabled.

17. What is an XML schema?

An XML schema provides the definition of an XML document. This implies that an XML schema defines the following in an XML document:

  • The elements that can appear in an XML document.
  • The attributes that can appear in an XML document.
  • The elements that are child elements.
  • The order of child elements.
  • The number of child elements.
  • Whether an element is empty or it includes some text.
  • The data types for elements and attributes.

18. State the advantages of XML schemas over DTD.

Microsoft developed a language known as the XML Schema Definition (XSD) to describe the schema to an XML document. The following are the advantages of XML schemas over DTDs:

  • XSD keeps much better control over types of data than the DTD.
  • DTD does not allow creating customized data types while the XSD provides full support to create customized data types.
  • XSD allows you to specify restrictions on data. It means that you can define the type of data that should be stored in an element, for example numbers or alphabets.
  • The XSD is quite easy to learn and to understand because its syntax is same as that of the XML document.

19. Using XSLT, how would you extract the value of a specific attribute from an element in an XML document?

The components necessary for the above mentioned operation are as follows:

  • The template element – Matches the correct XML element.
  • The value-of element – Selects the attribute value.
  • The optional apply-templates element – Allows continuous processing of the document

20. Which classes are supported to make an XML DOM?

The following are the different classes in the System.Xml namespace that make up the XML DOM:

  • The XmlNode class
  • The XmlDocument Class
  • The XmlElement Class
  • The XmlAttribute Class
  • The XmlText class
  • The XmlComment class
  • The XmlNodeList Class

21. Which class is used to encode and decode XML names and contains different methods to convert between CLR types and XSD types.

The XmlConvert Class.

22. What is the DTD?

The DTD is Document Type Definition that describes the formation of the content of an XML document. The DTD manages the data to store in a consistent format. It defines the XML elements and attributes about how they should be present in XML documents and what relation they should have with other elements and attributes. The DTD also allows you to mention whether an XML element is optional or not. If the XML documents are not according to the DTD rules, they are not considered valid.

23. Is it true that the XML’s goal is to replace HTML?

No, it is not true. Both are necessary in their respective fields.

24. What is XSLT?

XSLT is Extensible Stylesheet Language Transformations that is a part of XML, which is a mechanism to transform an XML document into another XML or HTML document.

25. Describe the rules and regulations that must be followed while creating a well-formed XML document.

The following are the rules and regulations that are necessary to follow while creating a well-formed XML document:

  • Every start tag must end with an end tag.
  • A root element should be included for enclosing other child elements.
  • XML tags are case-sensitive; therefore, start and end tags must be of same spelling and the casing should also be the same.
  • XML’s empty tags are necessary to close with a forward slash (/).
  • XML’s attributes values are necessary to enclose within double quotation marks.
  • XML tags must be properly nested. It means starting tags should be closed in the reverse order in which they present.

26. What are the naming conventions required for XML elements tags?

The following are the naming conventions that need to be followed for XML elements tags:

  • Element names should contain only characters, numbers, hyphens, and periods.
  • Element names cannot not begin with a number or punctuation character.
  • Element names must not start with the word xml (or XML, or Xml).
  • Element names cannot consist spaces.
  • Element names can be used any words except xml, XML, or Xml because no words are reserved in XML.

27. The XML preserves white spaces. Is it true?

Yes, it is true.

28. Explain the XML elements.

The elements are the central units of an XML document that explain and identify data. The elements are represented by the tags. You can also make your own tags, which make XML a user-friendly language. By creating custom meaningful elements, you can improve readability of the document. XML elements can be nested and the nested elements are known as child elements.


No comments

Leave a Reply

− 1 = 6