XML interview questions

  1. What is the difference between SAX parser and DOM parser?
  2. What is the difference between Schema and DTD?
  3. How do you parse/validate the XML document?
  4. What is XML Namespace?
  5. What is Xpath?
  6. What is XML template?
  7. How would you produce PDF output using XSL’s?
  8. What are the steps to transform XML into HTML using XSL?
  9. What is XSL?
  10. What is XSLT?
This entry was posted in General, Web dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

14 Comments on XML interview questions

  1. Revathi
    Posted 6/20/2005 at 12:06 am | Permalink

    What is the difference between SAX parser and DOM parser?

    DOM:

    creates an internal representation of an XML document

    -Nice for smaller XML files, but because of the whole XML file
    representation is in memory, it is possible not useful for
    very large documents

    -good for representation of an XML document.

    SAX:

    Event driven, so reacting when it finds certain elements in the XML
    code (e.g. tags,
    properties, …)

    goes from top to bottom, and if it encounters

    e.g. begintag, it fires an event.
    e.g. end tag, it fires and event.
    e.g. begin of file, it fires an event

  2. black_fury
    Posted 6/26/2005 at 7:46 pm | Permalink

    1.
    DOM parser - reads the whole XML document and returns a DOM tree representation of xml document. It provides a convenient way for reading, analyzing and manipulating XML files. It is not well suited for large xml files, as it always reads the whole file before processing.
    SAX parser - works incrementally and generate events that are passed to the application. It does not generate data representation of xml content so some programming is required. However, it provides stream processing and partial processing which cannot be done alone by DOM parser.

  3. Posted 6/26/2005 at 7:49 pm | Permalink

    What is Xpath?

    XPath is used to navigate through elements and attributes in an XML document.

  4. Posted 6/26/2005 at 7:53 pm | Permalink

    What is XSL?

    XSLT - a language for transforming XML documents
    XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element.

    XPath - a language for navigating in XML documents
    XSL-FO - a language for formatting XML documents

  5. Orca
    Posted 7/28/2005 at 6:46 pm | Permalink

    A DTD is:

    The XML Document Type Declaration contains or points to markup declarations that provide a grammar for a class of documents. This grammar is known as a document type definition or DTD.

    The DTD can point to an external subset containing markup declarations, or can contain the markup declarations directly in an internal subset, or can even do both.

    A Schema is:

    XML Schemas express shared vocabularies and allow machines to carry out rules made by people. They provide a means for defining the structure, content and semantics of XML documents.

    In summary, schemas are a richer and more powerful of describing information than what is possible with DTDs.

  6. Orca
    Posted 7/28/2005 at 6:48 pm | Permalink

    How Schemas Differ from DTDs
    The first, and probably most significant, difference between XML Schemas and XML DTDs is that XML Schemas use XML document syntax. While transforming the syntax to XML doesn’t automatically improve the quality of the description, it does make those descriptions far more extensible than they were in the original DTD syntax. Declarations can have richer and more complex internal structures than declarations in DTDs, and schema designers can take advantage of XML’s containment hierarchies to add extra information where appropriate — even sophisticated information like documentation. There are a few other benefits from this approach. XML Schemas can be stored along with other XML documents in XML-oriented data stores, referenced, and even styled, using tools like XLink, XPointer, and XSL.

    The largest addition XML Schemas provide to the functionality of the descriptions is a vastly improved data typing system. XML Schemas provide data-oriented data types in addition to the more document-oriented data types XML 1.0 DTDs support, making XML more suitable for data interchange applications. Built-in datatypes include strings, booleans, and time values, and the XML Schemas draft provides a mechanism for generating additional data types. Using that system, the draft provides support for all of the XML 1.0 data types (NMTOKENS, IDREFS, etc.) as well as data-specific types like decimal, integer, date, and time. Using XML Schemas, developers can build their own libraries of easily interchanged data types and use them inside schemas or across multiple schemas.

    The current draft of XML Schemas also uses a very different style for declaring elements and attributes to DTDs. In addition to declaring elements and attributes individually, developers can create models — archetypes — that can be applied to multiple elements and refined if necessary. This provides a lot of the functionality SOX had developed to support object-oriented concepts like inheritance. Archetype development and refinement will probably become the mark of the high-end schema developer, much as the effective use of parameter entities was the mark of the high-end DTD developer. Archetypes should be easier to model and use consistently, however.

    XML Schemas also support namespaces, a key feature of the W3C’s vision for the future of XML. While it probably wouldn’t be impossible to integrate DTDs and namespaces, the W3C has decided to move on, supporting namespaces in its newer developments and not retrofitting XML 1.0. In many cases, provided that namespace-prefixes don’t change or simply aren’t used, DTD’s can work just fine with namespaces, and should be able to interoperate with namespaces and schema processing that relies on namespaces. There will be a few cases, however, where namespaces may force developers to use the newer schemas rather than the older DTDs.

  7. Orca
    Posted 7/28/2005 at 6:53 pm | Permalink

    How do you parse/validate the XML document?

    The only way to validate an XML file is to parse the XML document using the DOM parser or the SAX parser.

  8. Orca
    Posted 7/28/2005 at 6:58 pm | Permalink

    What is XML Namespace?

    The XML namespaces recommendation defines a way to distinguish between duplicate element type and attribute names. Such duplication might occur, for example, in an XSLT stylesheet or in a document that contains element types and attributes from two different DTDs.

    An XML namespace is a collection of element type and attribute names. The namespace is identified by a unique name, which is a URI. Thus, any element type or attribute name in an XML namespace can be uniquely identified by a two-part name: the name of its XML namespace and its local name. This two-part naming system is the only thing defined by the XML namespaces recommendation.

    XML namespaces are declared with an xmlns attribute, which can associate a prefix with the namespace. The declaration is in scope for the element containing the attribute and all its descendants. For example:

    <!– Declares two XML namespaces. Their scope is the A and B elements. –>
    <A xmlns:foo=”http://www.foo.org/” xmlns=”http://www.bar.org/”>
    <B>abcd</B>
    </A>

    If an XML namespace declaration contains a prefix, you refer to element type and attribute names in that namespace with the prefix. For example:

    <!– A and B are in the http://www.foo.org/ namespace, which is associated with the foo prefix. –>
    <foo:A xmlns:foo=”http://www.foo.org/”>
    <foo:B>abcd</foo:B>
    </foo:A>

    If an XML namespace declaration does not contain a prefix, the namespace is the default XML namespace and you refer to element type names in that namespace without a prefix. For example:

    <!– This is equivalent to the previous example but uses a default namespace instead of the foo prefix. –>
    <A xmlns=”http://www.foo.org/”>
    <B>abcd<B>
    </A>

    1.2) Can you give me an executive summary of what XML namespaces are not?

    They aren’t a cure of cancer, they aren’t a way to win the lottery, and they aren’t a direct cause of world peace. They also aren’t very difficult to understand or use. Two things that XML namespaces are not have caused a lot of confusion, so we’ll mention them here:

    XML namespaces are not a technology for joining XML documents that use different DTDs. Although they might be used in such a technology, they don’t provide it themselves.

    The URIs used as XML namespace names are not guaranteed to point to schemas, information about the namespace, or anything else — they’re just identifiers. URIs were used simply because they’re a well-known system for creating unique identifiers. Don’t even think about trying to resolve these URIs. (For details, see question 12.4.)

  9. Orca
    Posted 7/28/2005 at 7:00 pm | Permalink

    XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer.

  10. Orca
    Posted 7/28/2005 at 7:14 pm | Permalink

    Generating PDF from XML
    Today, the most common application of XSL-FO is to produce Adobe PDF documents from the source XML files. Here is the two step process that is used to turn XML into PDF:

    Step 1. XML to XSL-FO using XSLT:
    The first step is to transform XML into XSL-FO format document. XSL-FO, like XSLT, makes use of XML syntax. The obvious choice here is to use XSLT to transform XML into XSL-FO. However, if you want, you can use some other method, such as DOM- or SAX-based processing the XML document, and generating XSL-FO document. In this article, we’ll use XSLT to transform XML into XSL-FO. XSLT transformation engine, such as MSXML, Xalan, Saxon, XT, etc. can be used to apply the XSLT stylesheet on the XML document.

    XSL-FO document describes the details of the presentation, such as physical size of the page, pagination details, margins, fonts, font sizes, colors, and so on. These characteristics are expressed using XSL formatting objects (for example: fo:page-sequence, fo:block, fo:footnote, fo:float, fo:region-body, and so on) and formatting properties (for example: background-attachment, background-color, font-family, text-depth, and so on). If you are know CSS (Cascading Style Sheets), the XSL formatting properties should sound familiar, however it is important to realize that XSL-FO provides a more sophisticated layout model than the CSS, and that XSL-FO is specifically designed to be used for generating fine-grained presentational layout files.

    Step 2. Processing XSL-FO using Formatting Engine (or Formatter):
    Once you have the XSL-FO document, XSL rendering engine, such as FOP or XSL Formatter (see XSL-FO Tools section below) can be used to convert XSL-FO elements into a PDF, PostScript, RTF or any other such print format.

    XSL-FO is not meant to be hand-coded. Generally, XSLT stylesheet will be written to transform XML into XSL-FO. The rendering engine is then used to convert XSL-FO into the required print documents. External resources (such as images and fonts) can be referred in the XSL-FO document. SVG elements can be used inside XSL-FO document to produce vector graphics (such as charts or maps).

  11. Harcharansingh
    Posted 11/28/2005 at 4:48 am | Permalink

    I have confusion in giving link to ref link to note in xsl file as in dtd they have define varities of type for ref tag and note. Above are the tag

    I also confused in xref tag whwn this is in used

    Please clarify the above dout

  12. Desi Dimova
    Posted 4/5/2006 at 9:19 pm | Permalink

    1. What is the difference between SAX parser and DOM parser?
    DOM spec defines an object-oriented hieararchy.
    The DOM parser creates an internal tree based on the hierarchy of the XML data.
    Tree stays in memory until released. The DOM parser is more memory intensive. DOM Parser’s advantage is that it is simple. Pairs nicely with XSLT.

    SAX spec defines an event based approach, calling handler functions whenever certain text nodes or processing instructions are found. These events include the start and end of the document, finding a text node, finding child elements, and hitting a malformed element. SAX development is more challenging. SAX can parse gigabytes worth of XML without hitting resource barriers. It’s also faster and more complex. Better for huge XML docs. Best suited for sequential-scan applications.

    2. What is the difference between Schema and DTD?
    Schema might outphase DTD. XML shemas are in XML. XML Schema has a lot of built-in data types including xs:string,xs:decimal,xs:integer,xs:boolean,xs:date,xs:time. XML schemas can be edited with Schema files, parsed with XML parser, manipulated with XML DOM, and transformed with XSLT.
    The building blocks of DTD include elements, attributes, entities, PCDATA, and CDATA.

    3. How do you parse/validate the XML document?
    By using a SAXParser, DOMParser, or XSDValidator.

    4. What is XML Namespace?
    Defining a namespace to avoid confusion involves using a prefix and adding an xmlns attribute to the tag to give the prefix a qualified name associated with the namespace. All child elements with the same prefix are associated with the namespace defined in the start tag of an element.

    5. What is Xpath?
    XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer.

    6. What is XML template?
    * A style sheets describes transformation rules
    * A transformation rule: a pattern + a template
    * Pattern: a configuration in the source tree
    * Template: a structure to be instantiated in the result tree
    * When a pattern is matched in the source tree, the corresponding pattern is generated in the result tree

    7. How would you produce PDF output using XSL’s?
    FOP it. =)
    -transform xml into xsl-fo doc using xslt, or DOM or SAX
    -process xsl-fo using a Formatter to convert xsl-fo into a pdf.

    8. What are the steps to transform XML into HTML using XSL?
    An XSLT processor may output the result tree as a sequence of bytes.The xsl:output element allows stylesheet authors to specify how they wish the result tree to be output. If an XSLT processor outputs the result tree, it should do so as specified by the xsl:output element; however, it is not required to do so.The method attribute on xsl:output identifies the overall method that should be used for outputting the result tree.
    The html output method outputs the result tree as HTML; for example,

    9. What is XSL?
    In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

    10. What is XSLT?
    A language for transforming XML documents into other XML documents. XSLT is designed for use as part of XSL, which is a stylesheet language for XML.

  13. Anurag
    Posted 2/20/2007 at 6:52 am | Permalink

    fabulous….these questions are really very important to understand most of the people who are working on xml,xslt and xsd dont know exactly how the things are working in backdrop and what these things are donig exactly the explanation given by the every one is really good, its a good stuff to clear an interview on xml….thanks for providing all needed information in such a very good manner.

  14. Vicky
    Posted 6/30/2007 at 2:24 am | Permalink

    Hi All :

    Here is Milestone for you;

    What is the difference between Name and ID that we passed to document element.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*