XmlNodeReader.XmlLang Property
Overview
Gets the current xml:lang
scope for the node being read.
Namespace: System.Xml
Assembly: System.Xml.ReaderWriter.dll
Syntax
public string XmlLang { get; }
Return Value
Type: String
Returns the value of the xml:lang
attribute on the current node or the nearest ancestor that defines it. Returns an empty string if the attribute is not present.
Remarks
The XmlLang
property reflects the value of the xml:lang
attribute according to the XML Namespaces specification. It can be used to determine the language of the current element when processing multilingual XML documents.
This property is read‑only; its value changes automatically as the reader moves through the XML document.
Example
The following example demonstrates how to read the xml:lang
value using XmlNodeReader
:
using System;
using System.Xml;
class Program
{
static void Main()
{
string xml = @"
<books xml:lang='en'>
<book>
<title xml:lang='fr'>Le Petit Prince</title>
<author>Antoine de Saint‑Exupéry</author>
</book>
</books>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
using (XmlNodeReader reader = new XmlNodeReader(doc))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
Console.WriteLine($""Element: {reader.Name}, xml:lang = '{reader.XmlLang}'"");
}
}
}
}
}