Normally, XML is stored in a Unicode string which is mapped via ADO.NET to .NET
System.String
. Then you can parse this string as XML. All XML parser can parse from any input stream. If you have a string representing XML content (not XML file, as in other cases), you can put the stream data in an instance of
System.IO.MemoryStream
:
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx[
^].
You can find a short code sample on how to work with the stream if you have a string:
http://stackoverflow.com/questions/8143732/stringstream-in-c-sharp[
^].
If, by some reason, you store XML as binary data (using BLOB data type), you still can use memory stream, which you initialize with raw data in the form of array of bytes, which you can obtain using ADO.NET
DataReader
. Please see this Microsoft article:
http://msdn.microsoft.com/en-us/library/87z0hy49.aspx[
^].
Now, you need to take one of XML parsers, initialize it from stream and parse it. What type of parser to choose? This is my short overview of them:
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
Good luck,
—SA