Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to calculate the size of an xml if it is loaded into XmlReader?

Tags:

c#

.net

vb.net

I am trying to find out if there is a way to calculate the file size from XmlReader. I don't see anything on the reader object that helps determine the size. Any ideas? Thank you!

Using reader As Xml.XmlReader = GetXML(columnName.ToString())

End Using
like image 508
Jyina Avatar asked Dec 09 '13 21:12

Jyina


People also ask

What's the difference between XmlDocument and XmlReader?

Based on my understanding of the two classes, XmlReader should perform faster in my scenario because it reads through an XML document only once, never storing more than the current node in memory. On the contrary, XmlDocument stores the whole XML file in memory which has some performance overhead.

How big is an XML file?

There is no limit of XML file size but it takes memory (RAM) as file size of XML file, so long XML file parsing size is performance hit. It is advised to long XML size using SAX for . NET to parse long XML documents.

What is the difference between XDocument and XmlDocument?

XDocument is from the LINQ to XML API, and XmlDocument is the standard DOM-style API for XML. If you know DOM well, and don't want to learn LINQ to XML, go with XmlDocument .


1 Answers

XmlReader might not read from something that has a known or definite size. Your best bet would be to do something with the source of whatever the XmlReader is reading. E.g. you might have a Stream and try to get Stream.Length (some streams don't support this, as they don't have a length). This will require modifying GetXML.

like image 97
Tim S. Avatar answered Oct 29 '22 21:10

Tim S.