Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
string xmlFrag ="<book genre='novel' misc='sale-item &h; 1987'></book>";
XmlParserContext context;
string subset = "<!ENTITY h 'hardcover'>";
context = new XmlParserContext(null, null, "book", null, null, subset, "", "", XmlSpace.None);
reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);
reader.MoveToContent();
reader.MoveToAttribute("misc");
while (reader.ReadAttributeValue()){
if (reader.NodeType==XmlNodeType.EntityReference)
Console.WriteLine("{0} {1}", reader.NodeType, reader.Name);
else
Console.WriteLine("{0} {1}", reader.NodeType, reader.Value);
}
}
finally
{
if (reader != null)
reader.Close();
}
}
}
Related examples in the same category