Gets the current xml:lang scope.
using System;
using System.IO;
using System.Xml;
public class Sample{
public static void Main(){
string xmlFrag = "<book xml:lang='en-US'> " +
" <title xml:lang='en-GB'>Colour Analysis</title>" +
" <title>C#</title>" +
"</book>";
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read()){
switch (reader.NodeType){
case XmlNodeType.Element:
Console.WriteLine("{0}: <{1}>", reader.XmlLang, reader.Name);
break;
case XmlNodeType.Text:
Console.WriteLine("{0}: {1}", reader.XmlLang, reader.Value);
break;
case XmlNodeType.EndElement:
Console.WriteLine("{0}: </{1}>", reader.XmlLang, reader.Name);
break;
}
}
reader.Close();
}
}
Related examples in the same category