Interview Q&A · questions with model answers

XML Interview Questions

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked What's the difference between well-formed and valid XML?

    Well-formed XML follows the syntax rules of the XML specification: a single root element, properly nested and closed tags, quoted attribute values, and escaped special characters. Valid XML is…

  2. Most asked Compare DOM, SAX and StAX (or pull parsing).

    DOM (Document Object Model) loads the entire XML document into an in-memory tree, providing random access and XPath support but consuming 5–10x the file size in memory. SAX (Simple API for XML) is…

  3. Most asked Which characters must be escaped in XML, and what is CDATA?

    In XML text content and attribute values, & must be written as & and < as <. Inside attribute values, the quote character used as the delimiter must also be escaped (" or '). CDATA…

  4. Most asked Compare DTD, XML Schema (XSD), RELAX NG and Schematron.

    DTD is the original schema language — non-XML syntax, no data types, no namespace support, and entity features that introduce security risks. XSD (XML Schema) is the enterprise standard with XML…

  5. Most asked What's the difference between SOAP and REST?

    SOAP is an XML messaging protocol with a structured Envelope (Header + Body), formal contracts defined in WSDL/XSD, standardized fault elements for errors, and WS-* extensions for message-level…

  6. When should you use an element and when an attribute?

    Use attributes for simple, single-valued metadata about an element — identifiers, codes, units, and versions. Use elements for the actual data content, anything that can repeat, may need…

  7. How do you group data in XSLT 1.0 vs 2.0/3.0?

    XSLT 1.0 has no built-in grouping instruction, so you use the Muenchian method: declare an xsl:key, then select the first node of each group using generate-id() = generate-id(key('k',…

  8. How do absent, empty and nil elements differ?

    Absent means the element is not in the document at all (no information). Empty means the element is present but contains nothing: <x/> or <x></x>, representing an empty string. Nil means the element…

  9. How do you parse XML in Python? Compare ElementTree and lxml.

    Python's standard library provides xml.etree.ElementTree for basic XML parsing, building, and serialization with a limited XPath subset. The third-party lxml library offers the same API plus full…

  10. Which XML APIs does PHP provide?

    PHP provides five XML APIs built on libxml2: SimpleXML for quick object-style reading, DOMDocument with DOMXPath for full tree manipulation and XPath queries, XMLReader for streaming large files…

Was this page helpful?

Report a mistake