-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-System.Xml
Milestone
Description
The XmlReader.MoveToContent Method page has example code line: 3465 that can throw the exception System.Xml.XmlException.
This can happen when using a reader that has its conformance level set to document OR reusing a reader initialized with conformance level set to auto.
The example should demonstrate using a reader with Settings.ConformanceLevel set to ConformanceLevel.Fragment. The code will then "handle the following inputs without breaking".
This was tested with the following code:
XmlReader reader = XmlReader.Create("Test.xml", new()
{
IgnoreProcessingInstructions = true,
IgnoreWhitespace = true,
ConformanceLevel = ConformanceLevel.Fragment,
});
byte[] bytes = Encoding.UTF8.GetBytes(
@"""
<?xml version=""1.0""><!DOCTYPE price SYSTEM
""abc""><price>123.4</price>
""");
reader = XmlReader.Create(new MemoryStream(bytes));
// Exception thrown here:
if (reader.MoveToContent() == XmlNodeType.Element && reader.Name == "price")
{
var foo = reader.ReadString();
}Metadata
Metadata
Assignees
Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-System.Xml