Hi
Is it possible to find out the output size of an XmlDocument object?
I mean, a good-enough approach is this:
XmlDocument doc = new XmlDocument();
// load data in doc
int length = doc.OuterXml.Length;
1.Advantages:
1.1. It's an approximate value, but the approximation is very good, so I put this as an advantage
1.2. A single line of code to get the length:
int length = doc.OuterXml.Length;
2. Disadvantages:
2.1. OuterXml property is a calculated value. This means:
2.1.1. Extra computation
2.1.2. Extra memory
When dealing with small xml's, the solution is relatively ok.
But when dealing with large (huge) xml's, this solution is not a solution anymore. This is because OuterXml in fact returns a string, even if I don't need its data, but its length.
It's almost obvious to me that we couldn't eliminate the factor 2.1.1 from disadvantages list, but it seems to me the factor 2.1.2 is likely to be improved.
So, I'm searching a way to compute the length of this string by generating it in chunks. That is, I want to "reinvent" the OuterXml, but in several linked steps.
Put it in another way, I want to "stream" this property.
Accessing OuterXml in a stream-like fashion could also help in (de)crypting / (de)compressing it.
Any idea?
Thanks.