Skip to content

32. XPathDoc/XmlDoc, XML Frag/Doc, Canonical

March 27, 2011

94. What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
XPathDocument provides a fast, read-only, in-memory representation of an XML document by using XPath data model. XmlDocument implements the W3C DOM Level 1 Core and Core DOM Level 2. DOM is an in-memory (cache) tree representation of an XML document and enables the navigation and editing of the document. Because XmlDocument implements the IXPathNavigable interface it can also be used as the source document for the XslTransform class. The XmlDataDocument class extends XmlDocument and allows structured data to be stored, retrieved, and manipulated through a relational DataSet. This class allows components to mix XML and relational views of the underlying data. If the document needs to be changed use XmlDocument class if read-only fast forward use XPathDocument. 

95. What is the difference between an XML “Fragment” and an XML “Document”.
An XML Fragment is a piece of XML that is not a fully conformant XML Document. An example of this is when the XML does not have one root element.
Here is an example of an XML fragment: “<foo></foo><bar></bar>”
An XML Document usually begins with a declaration, identifies it and version type. A namespace can be used. There is a root node and the document is composed of markup and content. The most common form of markup are elements. Delimited by angle brackets, most elements identify the nature of the content they surround. Elements can contain attributes, they are name value pairs that occur inside start tags after the element name.

96. What does it mean to say “the canonical” form of XML?
According to W3C, if two XML documents have the same canonical form, then the two documents are logically equivalent within the given application context(except for limitations regarding a few unusual cases). Canonical XML is a subset or profile of XML. Converting an XML document to canonical XML is a good way to determine whether two XML documents are logically “the same document” despite differences of detail, such as differences in white spaces. Canonical XML specifies a number of details, some of which are: the UTF-8 encoding is used, line ends are represented using the character 0x0A, whitespace in attribute values is normalized, entity references are expanded, CDATA marked sections are not used, empty elements are encoded as start/end pairs, not using the special empty-element syntax, default attributes are made explicit, superfluous namespace declarations are deleted.

Happy Programming! =)
Source: Mainly MSDN and wikipedia.


From → OOP

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: