Friday, January 13, 2006

Just a discussion on what to use for reading XML....

From: Venkataramani, Kannan (Infosys) Sent: 14 December 2005 10:08To: 'Vikram Abrol'Subject: RE: Fetching XML data
Hi Vikram,

Q1. XpathDocument is a light weight class.

This means that the class does not have numerous methods and properties that consume more memory when you iniialize an instance of a class.
The object of this class are so less.

XPathDocument Class
XPathDocument Constructor
XPathDocument Constructor (Stream)
XPathDocument Constructor (String)
XPathDocument Constructor (TextReader)
XPathDocument Constructor (XmlReader)
XPathDocument Constructor (String, XmlSpace)
XPathDocument Constructor (XmlReader, XmlSpace)
Methods
XPathDocument.CreateNavigator Method

It just has one simple method and no properties as well, this is the meaning of a light weight class.

Q2. Less Footprint

When ever you try to work with XML data using different class, what happens is this, the XML document is de-serialized or read based on the type of parsing you use, during this operation, the elements are either stored as string equivalents then boxed and unboxed as and when required.
the XPathDocument has the schema information stored and the corresponding elements are stored as CLR equivalents.

So Footprint means this class trying to box and unbox variables, this requires some CPU time as well as memory, the less the memory used, less is the footprints.

In simple terms, you go to different shops to buy different items, you have more footprints than buying all items in the same shop.

Q3. Xpath and Xquery

i have a couple of links for you, these might xplain u better.
http://www.xml.com/pub/a/2002/01/02/xquery.html
http://www.db2mag.com/story/showArticle.jhtml?articleID=12803228
http://www.gnu.org/software/qexo/XQuery-Intro.html

What reader to use to read XML files.

CHOICES
PROS
CONS
XmlTextReader
-Fastest-Most efficient (memory)-Extensible
-Forward-only-Read-only-Requires manual validation
XmlValidatingReader
-Automatic validation-Run-time type info-Relatively fast & efficient(compared to DOM)
-2 to 3x slower than XmlTextReader-Forward-only-Read-only
XmlDocument (DOM)
-Full traversal -Read/write -XPath expressions
-2 to 3x slower than XmlTextReader/XmlValidatingReader-More overhead than XmlTextReader/XmlValidatingReader
XPathNavigator
-Full traversal-XPath expressions-XSLT integration-Extensible
-Read-only -Not as familiar as DOM
XPathDocument
-Faster than XmlDocument -Optimized for XPath/XSLT
-Slower than XmlTextReader

Hope this helps you
Kannan.V
[MCSD.NET]
From: Vikram Abrol [mailto:Vikram_Abrol@infosys.com] Sent: 14 December 2005 05:43To: Kannan VSubject: RE: Fetching XML data
Thanks Kannan , it helps when you say performance of one is better than another , but if this is the case then when is XmlDocument used ?
A few q: inline also..

From: Kannan V Sent: Monday, December 12, 2005 7:20 PMTo: Vikram AbrolSubject: RE: Fetching XML data

Hi Vikram,

Generally in the set of close cut answers, the most appropriate and most performance oriented one will be the choice, look below for why C is the correct answer among all others.

Use XMLReader/XMLWriter in performance oriented scenarios. Validation could be performed with XMLValidatingReader. You will pay development cost for speed.
XPathDocument is a light weight class [ What do you mean by this ? ] and the reason you want to use it is this.Reasons:1. In .NET 2.0 it becomes Read/Write.2. XPathDocument optimized for XSLT and XPath processing, has less footprint [ What do you mean by saying it has less footprint ?, resulting in much better performance relative to XmlDocument. In some cases it will perform 10 times faster, and becomes even faster in Whidbey.3. In .NET 2.0 can be used with XQueries [ Is there any diff. between Xpath & Xquery ? ].

For more information on the different methods and their performance.
----------------------------------------------------------------------
Can you explain in simple terms the below gist ?
Check this blog http://blogs.msdn.com/mfussell/archive/2004/2/23.aspx , but would appreciate how XmlReader, XmlWriter and XPathDocument classes differ in performance in concept of having xml types used as CLR type ?

XmlReader, XmlWriter and importantly the XPathDocument classes all have schema information stored. This means that when you load an XML document from a validating reader with an associated schema, we are able to store the XML types as CLR types. For example if the XML schema indicates that the values are of type xs:int these are stored as CLR int types in the XPathDocument, rather than as untyped strings. Not only does this enable you to work with the types in your CLR language of choice, but it reduces the storage and working set of the document loaded into memory, dependent your type of data of course. Importantly if you apply an XSLT or XQuery to the XPathDocument and use this to generate another XPathDocument, these CLR types are “flowed” between components in that they are not first copied to string values and then reparsed through a text XML parser. This provides a significant performance improvement when chaining XML components together that utilize schema type information.
Hope this helps...
Kannan.V
[MCSD.net]

From: Vikram AbrolPosted At: Mon 12/12/2005 16:25Posted To: ASP-ASP.NetConversation: Fetching XML dataSubject: Fetching XML data
You are creating a Web site .

You receive product lists in the form of XML documents. You are creating a procedure to extract information from these XML documents according to criteria that your users will select.
When a user makes a request, you want the results of these requests to be returned as quickly
as possible.
What should you do?


Ans C is correct…

my Question is Why D is incorrect ??


A. Create an XmlDataDocument object and load it with the XML data.
Use the DataSet property of the object to create a DataSet object.
Use a SQL SELECT statement to extract the requested data.
B. Create an XmlDataDocument object and load it with the XML data.
Use the SelectNodes method of the object to extract the requested data.
C. Create an XPathDocument object and load it with the XML data.
Call the CreateNavigator method to create an XPathNavigator object.
Call the Select method of the XPathNavigator object to run an XPath query that extracts the
requested data.
D. Create an XmlReader object.
Use the Read method of the object to stream through the XML data and to apply an XPath
expression to extract the requested data.

Thursday, January 05, 2006