tags:

views:

12

answers:

1

I am creating an XML document line by line and need to keep an eye on how large this file is becoming. The resulting file will need to be sent via MSMQ which has a message size restriction of 4Mb I think. What I need to do is when the document is getting close to this size, is to stop adding data and to add the document to a list and start creating a new one with the remaining data. I can then return this list of XML documents to the calling function where the documents can be sent via MSMQ. My question is, what would be a good way of continuously monitoring the size of a XElement ?

A: 

XNode have ToString method

XElement xmlTree = new XElement("Root",
    new XElement("Child1", 1)
);
Console.WriteLine(xmlTree);

You can found size of each element you add.

Andrew