FullStackFSCCafé
 
 
Sign in with GoogleSign in with Google. Opens in new tab
Kill Your Tech Interview
3877 Full-Stack, Algorithms & System Design Interview Questions
Answered To Get Your Next Six-Figure Job Offer
      
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

29+ Advanced XML Interview Questions (ANSWERED) Web Devs Must Know

XML is used in thousands of different applications that store, handle, and transmit data. Reporting, ETL, Android and Java Development and many other use cases still rely on XML, XSLT and XPath as underlying tech stack. Follow along and learn 29 most advanced XML Interview Questions and Answers (including XSLT and XPath) for your next tech interview.

Q1: 
When would I use XML instead of SQL?

Answer

XML is not a database. It was never meant to be a database. It is never going to be a database. Relational databases are proven technology with more than 20 years of implementation experience. They are solid, stable, useful products. They are not going away. XML is a very useful technology for moving data between different databases or between databases and other programs. However, it is not itself a database. Don't use it like one.

You can build a DBMS with a DOM/XPath interface but to get ACID properties or scale to large data sets you need to implement a DBMS engine and a data format with indexes, logging and other artifacts of a DBMS - which (by definition) makes it something other than XML.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q2: 
What characters do I need to escape in XML documents?

Answer

If you use an appropriate class or library, they will do the escaping for you. Many XML issues are caused by string concatenation.

  1. Always
    • Escape < as &lt; unless < is starting a <tag/>
    • Escape & as &amp; unless & is starting an &entity;
  1. Attribute Values
    • attr=" 'Single quotes' are ok within double quotes."
    • attr=' "Double quotes" are ok within single quotes.'
    • Escape " as &quot; and ' as &apos; otherwise.
  1. Comments, CDATA, and Processing Instructions
    • <!-- Within comments --> nothing has to be escaped but no -- strings are allowed.
    • <![CDATA[ Within CDATA ]]> nothing has to be escaped, but no ]]> strings are allowed.
    • <?PITarget Within PIs ?> nothing has to be escaped, but no ?> strings are allowed.
  1. Esoterica
    • Escape ]]> as ]]&gt; unless ]]> is ending a CDATA section. This rule applies to character data in general – even outside a CDATA section.

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q3: 
What is XPath?

Answer

XPath is an important and core component of XSLT standard. It is used to traverse the elements and attributes in an XML document.

XPath is a W3C recommendation. XPath provides different types of expressions to retrieve relevant information from the XML document. It is syntax for defining parts of an XML document.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q4: 
What is XSLT?

Answer

Before XSLT, first we should learn about XSL. XSL stands for EXtensible Stylesheet Language. It is a styling language for XML just like CSS is a styling language for HTML. XSLT stands for XSL Transformation. It is used to transform XML documents into other formats (like transforming XML into HTML).

In HTML documents, tags are predefined but in XML documents, tags are not predefined. World Wide Web Consortium (W3C) developed XSL to understand and style an XML document, which can act as XML based Stylesheet Language. An XSL document specifies how a browser should render an XML document.

The XSLT stylesheet is written in XML format. It is used to define the transformation rules to be applied on the target XML document. The XSLT processor takes the XSLT stylesheet and applies the transformation rules on the target XML document and then it generates a formatted document in the form of XML, HTML, or text format. At the end it is used by XSLT formatter to generate the actual output and displayed on the end-user.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q5: 
What is the difference between XML and XSD?

Answer

XSD (XML Schema Definition) specifies how to formally describe the elements in an Extensible Markup Language (XML) document. XML was designed to describe data.

Actually the XSD is XML itself. Its purpose is to validate the structure of another XML document. The XSD is not mandatory for any XML, but it assures that the XML could be used for some particular purposes. The XML is only containing data in suitable format and structure.

Differences:

  • XSD is based and written on XML.
  • XSD defines elements and structures that can appear in the document, while XML does not.
  • XSD ensures that the data is properly interpreted, while XML does not.
  • An XSD document is validated as XML, but the opposite may not always be true.
  • XSD is better at catching errors than XML.

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q6: 
Compare XML to JSON

Answer

JSON Pro:

  • Simple syntax, which results in less "markup" overhead compared to XML.
  • Easy to use with JavaScript as the markup is a subset of JS object literal notation and has the same basic data types as JavaScript.
  • JSON Schema for description and datatype and structure validation
  • JsonPath for extracting information in deeply nested structures JSON Con:

  • Simple syntax, only a handful of different data types are supported.

  • No support for comments.

XML Pro:

  • Generalized markup; it is possible to create "dialects" for any kind of purpose
  • XML deals remarkably well with the full richness of unstructured data CDATA
  • XML Schema for datatype, structure validation. Makes it also possible to create new datatypes
  • XSLT for transformation into different output formats
  • XPath/XQuery for extracting information in deeply nested structures
  • built in support for namespaces

XML Con:

  • Relatively wordy compared to JSON (results in more data for the same amount of information).
  • XML presents a 21% overhead over JSON
  • Requires some reasonable more time to compress.

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q7: 
Create XML based on DTD

Problem

Lets see a very simple example in which university has multiple students and each student has two elements "name" and "year".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE university[              // --> university as root element 
<!ELEMENT university (student*)>   // --> university has  * = Multiple students
<!ELEMENT student (name,year)>     // --> Student has elements name and year
<!ELEMENT name (#PCDATA)>          // --> name as Parsed character data
<!ELEMENT year (#PCDATA)>          // --> year as Parsed character data
]>

Could you create XML based on this DTD?

Answer

Consider:

<university>
    <student>
        <name>
            John Niel             //---> I can also use an Integer,not good
        </name>
        <year>
            2000                 //---> I can also use a string,not good
        </year>
    </student>
</university>

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q8: 
Create XPath to select Element by attribute value

Problem

I have following XML:

<?xml version="1.0" encoding="UTF-8"?>
<Employees>
    <Employee id="3">
        <age>40</age>
        <name>Tom</name>
        <gender>Male</gender>
        <role>Manager</role>
    </Employee>
    <Employee id="4">
        <age>25</age>
        <name>Meghna</name>
        <gender>Female</gender>
        <role>Manager</role>
    </Employee>
</Employees>

How to select Employee element with id="4"?

Answer

Use:

/Employees/Employee[@id='4']

or

//Employee[@id='4']

// can be very slow because it searches the entire document for matching nodes. If the structure of the documents you're working with is going to be consistent, you are probably best off using a full path.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q9: 
Is there any difference between 'valid xml' and 'well formed xml'?

Answer

There is a difference, yes.

  • XML that adheres to the XML standard is considered well formed,
  • while xml that adheres to a DTD is considered valid.

Well-formedness is a prerequisite for validity. Validity refers to semantics, well-formedness refers to syntax.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q10: 
Transform this XML into HTML document

Problem

Consider:

<?xml version = "1.0"?>  
<class>   
   <employee id = "001">  
      <firstname>Aryan</firstname>   
      <lastname>Gupta</lastname>   
      <nickname>Raju</nickname>   
      <salary>30000</salary>  
   </employee>   
   <employee id = "024">   
      <firstname>Sara</firstname>   
      <lastname>Khan</lastname>   
      <nickname>Zoya</nickname>   
      <salary>25000</salary>  
   </employee>   
   <employee id = "056">   
      <firstname>Peter</firstname>   
      <lastname>Symon</lastname>   
      <nickname>John</nickname>   
      <salary>10000</salary>   
   </employee>   
</class>  

Define an XSLT stylesheet document for the above XML document. You should follow the criteria give below:

  • Page should have a title employee.
  • Page should have a table of employee's details.
  • Columns should have following headers: id, First Name, Last Name, Nick Name, Salary
  • Table must contain details of the employees accordingly.
Answer

Use this XSLT:

<?xml version = "1.0" encoding = "UTF-8"?>  
<!-- xsl stylesheet declaration with xsl namespace:   
Namespace tells the xlst processor about which   
element is to be processed and which is used for output purpose only   
-->   
<xsl:stylesheet version = "1.0"   
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">     
<!-- xsl template declaration:    
template tells the xlst processor about the section of xml   
document which is to be formatted. It takes an XPath expression.   
In our case, it is matching document root element and will   
tell processor to process the entire document with this template.   
-->   
   <xsl:template match = "/">   
      <!-- HTML tags   
         Used for formatting purpose. Processor will skip them and browser   
            will simply render them.   
      -->   
      <html>   
         <body>  
            <h2>Employee</h2>   
            <table border = "1">   
               <tr bgcolor = "#9acd32">   
                  <th>ID</th>   
                  <th>First Name</th>   
                  <th>Last Name</th>   
                  <th>Nick Name</th>   
                  <th>Salary</th>   
               </tr>   
               <!-- for-each processing instruction   
               Looks for each element matching the XPath expression   
               -->   
              <xsl:for-each select="class/employee">   
                  <tr>   
                     <td>   
                        <!-- value-of processing instruction   
                        process the value of the element matching the XPath expression   
                        -->   
                        <xsl:value-of select = "@id"/>   
                     </td>   
                     <td><xsl:value-of select = "firstname"/></td>   
                     <td><xsl:value-of select = "lastname"/></td>   
                     <td><xsl:value-of select = "nickname"/></td>   
                     <td><xsl:value-of select = "salary"/></td>     
                  </tr>   
               </xsl:for-each>   
            </table>   
         </body>   
      </html>   
   </xsl:template>    
</xsl:stylesheet>  

To apply this XSLT to XML update XML document with the following xml-stylesheet tag:

<?xml version = "1.0"?>   
<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>   
<class>   
...   
</class>  

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q11: 
What are some advantages of XSLT?

Answer

A list of advantages of using XSLT:

  • XSLT provides an easy way to merge XML data into presentation because it applies user defined transformations to an XML document and the output can be HTML, XML, or any other structured document.
  • XSLT provides Xpath to locate elements/attribute within an XML document. So it is more convenient way to traverse an XML document rather than a traditional way, by using scripting language.
  • XSLT is template based. So it is more resilient to changes in documents than low level DOM and SAX.
  • By using XML and XSLT, the application UI script will look clean and will be easier to maintain.
  • XSLT templates are based on XPath pattern which is very powerful in terms of performance to process the XML document.
  • XSLT can be used as a validation language as it uses tree-pattern-matching approach.
  • You can change the output simply modifying the transformations in XSL files.

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q12: 
What does [CDATA[]] in XML mean?

Answer

A CDATA section is "a section of element content that is marked for the parser to interpret as only character data, not markup." The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.

<![CDATA[
Within this Character Data block I can
use double dashes as much as I want (along with <, &, ', and ")
*and* %MyParamEntity; will be expanded to the text
"Has been expanded" ... however, I can't use
the CEND sequence. If I need to use CEND I must escape one of the
brackets or the greater-than sign using concatenated CDATA sections.
]]>

Or:

<description>An example of escaped CENDs</description>
<!-- This text contains a CEND ]]> -->
<!-- In this first case we put the ]] at the end of the first CDATA block
     and the > in the second CDATA block -->
<data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data>
<!-- In this second case we put a ] at the end of the first CDATA block
     and the ]> in the second CDATA block -->
<alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative>

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q13: 
What does “xmlns” in XML mean?

Answer

It defines an XML Namespace.

Basically, every element (or attribute) in XML belongs to a namespace, a way of "qualifying" the name of the element.

Imagine you and I both invent our own XML. You invent XML to describe people, I invent mine to describe cities. Both of us include an element called name. Yours refers to the person’s name, and mine to the city name—OK, it’s a little bit contrived.

<person>
    <name>Rob</name>
    <age>37</age>
    <homecity>
        <name>London</name>
        <lat>123.000</lat>
        <long>0.00</long>
    </homecity>
</person>

If our two XMLs were combined into a single document, how would we tell the two names apart? As you can see above, there are two name elements, but they both have different meanings.

The answer is that you and I would both assign a namespace to our XML, which we would make unique:

<personxml:person xmlns:personxml="http://www.your.example.com/xml/person"
                  xmlns:cityxml="http://www.my.example.com/xml/cities">
    <personxml:name>Rob</personxml:name>
    <personxml:age>37</personxml:age>
    <cityxml:homecity>
        <cityxml:name>London</cityxml:name>
        <cityxml:lat>123.000</cityxml:lat>
        <cityxml:long>0.00</cityxml:long>
    </cityxml:homecity>
</personxml:person>

Now we’ve fully qualified our XML, there is no ambiguity as to what each name element means. All of the tags that start with personxml: are tags belonging to your XML, all the ones that start with cityxml: are mine.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q14: 
What is Processing Instructions in XML?

Answer

Processing Instruction is defined in the XML standard, XML 1.0 Recommendation. The definition says: "Processing instructions (PIs) allow documents to contain instructions for applications… PIs are not part of the document's character data, but MUST be passed through to the application."

Following is the syntax of PI:

<?target instructions?>

And some examples:

<?display table-view?>
<?sort alpha-ascending?>
<?textinfo whitespace is allowed ?>
<?elementnames <fred>, <bert>, <harry> ?>

In the real world PIs are seldom used with a few common exceptions. The PI is the official method for an XML document to link to a stylesheet, and Microsoft uses PIs in MS Office 2003 to make it easy for MS Word and MS Excel documents to be identified when saved as XML:

<?xml-stylesheet href="mystyle.css" type="text/css"?>

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q15: 
What is meaning of

Answer

Think of XML as not a sequence of characters but a sequence of bytes. Imagine the system receiving the XML sees the bytes 195, 162. How does it know what characters these are? In order for the system to interpret those bytes as actual characters (and so display them or convert them to another encoding), it needs to know the encoding used in the XML.

An XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q16: 
What is the correct XPath for choosing attributes that contain “foo”?

Problem

Given this XML, what XPath returns all elements whose prop attribute contains Foo (the first three nodes):

<bla>
 <a prop="Foo1"/>
 <a prop="Foo2"/>
 <a prop="3Foo"/>
 <a prop="Bar"/>
</bla>
Answer

Use:

/bla/a[contains(@prop,'Foo')]

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q17: 
When to prefer JSON over XML?

Answer

Favor JSON over XML when all of these are true:

  • Messages don't need to be validated, or validating their deserialization is simple
  • You're not transforming messages, or transforming their deserialization is simple
  • Your messages are mostly data, not marked-up text
  • The messaging endpoints have good JSON tools

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q18: 
When to prefer XML over JSON?

Answer

Favor XML over JSON when any of these is true:

  • You need message validation
  • You're using XSLT
  • Your messages include a lot of marked-up text
  • You need to interoperate with environments that don't support JSON
  • You need to process the data on the client, and you can leverage XSL for that. Chances are the XML + XSL chain will work faster than JSON + JavaScript especially for big chunks of data.
  • One good case is to convert the data into an HTML snippet
  • Various legacy cases:
  • There is an existing XML service, and it is a hassle to rewrite it with JSON for some reasons.
  • You have to post this data back as XML after some light processing using user's input.

Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q19: 
XPath: How to check if an attribute exists?

Problem

Given the following XML, how do I write an XPath query to pull nodes where the attribute foo exists?

<node1>
  <node2>
    <node3 foo='bar'></node3>
    <node3></node3>
    <node3 bar='foo'></node3>
    <node3 foo='foobar'></node3>
  </node2>
</node1>
Answer

Short and sweet:

//*[@foo]

With [@attributeName] you get all nodes which have that attribute.


Having Tech or Coding Interview? Check 👉 41 XML & XSLT Interview Questions

Q20: 
Create DTD based on XML

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q21: 
Does a valid XML file require an XML declaration?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q22: 
How do I comment out a block of tags in XML?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q23: 
How to implement if-else statement in XSLT?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q24: 
What is difference between XML Schema and DTD?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q25: 
What's the difference between and ?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q26: 
What's the need for XHTML?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q27: 
XML best practices: attributes vs additional elements? Wha tis best practice?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q28: 
When would you use PIs in XML?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!

Q29: 
Why is XSLT so rarely used on the web?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers
 

Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...

Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...

Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...

Cosmos DB has gained popularity among developers and organizations across various industries, including finance, e-commerce, gaming, IoT, and more. Follow along and learn the 24 most common and advanced Azure Cosmos DB interview questions and answers...
More than any other NoSQL database, and dramatically more than any relational database, MongoDB's document-oriented data model makes it exceptionally easy to add or change fields, among other things. It unlocks Iteration on the project. Iteration f...
Unit Tests and Test Driven Development (TDD) help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outpu...
Domain-Driven Design is nothing magical but it is crucial to understand the importance of Ubiquitous Language, Domain Modeling, Context Mapping, extracting the Bounded Contexts correctly, designing efficient Aggregates and etc. before your next DDD p...
At its core, Microsoft Azure is a public cloud computing platform - with solutions including Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS) that can be used for services such as analytics, virtual c...
As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. Follow along to refresh your knowledge and explore the 52 most frequently asked and advanced Node JS Interview Questions and Answers every...
Dependency Injection is most useful when you're aiming for code reuse, versatility and robustness to changes in your problem domain. DI is also useful for decoupling your system. DI also allows easier unit testing without having to hit a database and...