posts - 50, comments - 154, trackbacks - 169

My Links

News

Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

Friends Blog

XML usage when and where in dotNet

XML usage when and where in dotNet

 

 

Classes with fields or properties that hold XML: If a class has a field or property that is an XML document or fragment, it should provide mechanisms for manipulating the property as both a string and as an XmlReader.

 

Methods that accept XML input or return XML as output: Methods that accept or return XML should favor returning XmlReader or XPathNavigator unless the user is expected to be able to edit the XML data, in which case XmlDocument should be used.

 

Converting an object to XML: If an object wants to provide an XML representation of itself for serialization purposes, then it should use the XmlWriter if it needs more control of the XML serialization process than what is provided by the XmlSerializer. If the object wants to provide an XML representation of itself that enables it to participate fully as a member of the XML world, such as allow XPath queries or XSLT transformations over the object, then it should implement the IXPathNavigable interface.

 

 

 

XMLReader: System.Xml.XmlReader:

 

1)  It is the pull model XML parser of .NET Framework, As needed data is pulled.

2)  Operates in a forward-only, streaming fashion while only showing information about a single node at any given time.

3)  It doesn't require that the entire XML document be loaded in memory.

4)  It is read-only.

 

XPathNavigator: System.Xml.XPath.XPathNavigator:

 

1)  It is a read-only cursor over XML data sources.

2)  It is random access to an underlying XML source.

3)  An XML cursor acts like a lens that focuses on one XML node at a time.

4)  The cursor can be positioned anywhere along the XML document at any given time (Which is draw back of XML Reader).

5)  It is read-only

6)  An example of using the this (XPathNavigator) to create an XML view of non-XML data is the ObjectXPathNavigator.

7)  It is iess palatable than using the XmlDocument or XmlNode as lacking of  InnerXML and OuterXML user friendly properties.

 

XmlWriter: System.Xml.XmlWriter:

 

1) This is only for writing and cannot be used for reading or processing.

2) It provides a generic mechanism for pushing an XML document into an underlying store

3) Underlying store can be anything from a file if using the XmlTextWriter to an XmlDocument if using the XmlNodeWriter.

4) Using an XmlWriter as a parameter to methods that return XML provides a robust way to support a wide range of possible return types including file streams, strings, and XmlDocument instances, Eg: XmlSerializer.Serialize() method uses this as one of parameter in its overload methods.

 

XmlDocument:  System.Xml.XmlDocument/XmlNode:

 

1) This is an implementation of the W3C Document Object Model (DOM). 

2) The DOM is an in-memory representation of an XML document made up of a hierarchical tree of XmlNode objects that represent logical components of the XML document, such as elements, attributes, and text nodes.

3) DOM is the most popular API for manipulating XML in the .NET Framework because it provides a straightforward way to load, process, and save XML documents.

4) The main drawback of the DOM is that its design requires the entire XML document to be loaded in-memory.

 

 

In general, If the XML is expected to be edited by the receiver, then an XmlDocument should be returned. Otherwise an XmlReader or XPathNavigator should be returned depending on whether or not the method needs to provide streaming, forward-only access to the XML data

 

If an object wants to provide an XML representation of itself for serialization purposes, then it should use the XmlWriter if it needs more control of the XML serialization process than is provided by the XmlSerializer. If the object wants to provide an XML representation of itself that enables it to participate fully as a member of the XML world, such as allow XPath queries or XSLT transformations over the object, then it should implement the IXPathNavigable interface.

 

For further reference - Look into this URL:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml03172004.asp

 

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Tuesday, March 23, 2004 12:07 PM | Filed Under [ C# ]

Feedback

Gravatar

# RE: XML usage when and where in dotNet

If you are going to copy someone else's work, make sure you let everyone know it, and put a link to it on your post.

This post was take from Dare's MSDN article: Best Practices for Representing XML in the .NET Framework: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml03172004.asp
3/23/2004 2:27 PM | don@donxml.com (DonXML Demsak)
Gravatar

# re: XML usage when and where in dotNet

This is abstract and I compiled it to make it on point basis. Thanks for observation, I will add the link.
3/23/2004 2:58 PM | brcraju
Gravatar

# re: XML usage when and where in dotNet

simply superb
4/20/2007 3:43 AM | seenu
Gravatar

# re: XML usage when and where in dotNet

superb piece of information with development point of view.
1/2/2011 5:11 AM | Ranjan Dubey
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: