-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Milestone
Description
There is a difference in reading content depending on the settings XmlReaderSettings
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
const string xml = "<test a=\"sdf\"/>";
//1
try
{
using var xmlReader = XmlReader.Create(new StringReader(xml));
xmlReader.MoveToContent();
xmlReader.MoveToAttribute(0);
if (xmlReader.ReadContentAs(typeof(XmlAtomicValue), null) is XmlAtomicValue xmlAtomic)
{
//{"Content cannot be converted to the type System.Xml.Schema.XmlAtomicValue. Line 1, position 7."}
Console.WriteLine(xmlAtomic.Value);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
//2
try
{
using var xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings {Async = true});
await xmlReader.MoveToContentAsync();
xmlReader.MoveToAttribute(0);
if (await xmlReader.ReadContentAsAsync(typeof(XmlAtomicValue), null) is XmlAtomicValue xmlAtomic)
{
//ok
Console.WriteLine(xmlAtomic.Value);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}Reactions are currently unavailable