Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlReaderSettings.MaxCharactersInDocument Property

Gets or sets a value indicating the maximum allowable number of characters XML document. A zero (0) value means no limits on the size of the XML document. A non-zero value specifies the maximum size, in characters.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public long MaxCharactersInDocument { get; set; }

Property Value

Type: System.Int64
The maximum allowable number of characters in an XML document. The default is 0.

A zero (0) value means no limits on the number of characters in the parsed document. A non-zero value specifies the maximum number of characters that can be parsed.

The maximum character count for the document includes the count of characters that result from expanded entities.

If the reader attempts to read a document with a size that exceeds this property, an XmlException will be thrown.

This property allows you to mitigate denial of service attacks where the attacker submits extremely large XML documents. By limiting the size of a document, you can detect the attack and recover reliably.


                string markup = "<Root>Content</Root>";


                XmlReaderSettings settings = new XmlReaderSettings();
                settings.MaxCharactersInDocument = 10;

                try
                {
                    using (XmlReader reader = XmlReader.Create(new StringReader(markup), settings))
                    {
                       while (reader.Read()) { }
                    }
                }
                catch (XmlException ex)
                {
                    OutputTextBlock.Text = ex.Message;
                }



Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.