Jyina
Jyina

Reputation: 2902

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

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

Upvotes: 5

Views: 5579

Answers (2)

Tim S.
Tim S.

Reputation: 56556

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.

Upvotes: 4

Bo TX
Bo TX

Reputation: 424

If you must use XmlReader as your source, this should get you close to the file size (c#):

int sizeInBytes = Encoding.ASCII.GetBytes(reader.ReadOuterXml()).Length;

Upvotes: 1

Related Questions