It is correct that you have to include the namespace, but the samples above do not work unless you put the namespace in curly braces:
XNameSpace ns = "http://www.lge.com/ddc";
foreach (XElement element in xdoc.Descendants("{" + ns + "}nationalList")
{
MessageBox.Show(element.ToString());
}
Greetings Christian
You have to use the namespace:
// do _not_ use var ns = ... here.
XNameSpace ns = "http://www.lge.com/ddc";
foreach (XElement element in xdoc.Descendants(ns + "nationalList")
{
MessageBox.Show(element.ToString());
}
If you don't want to have to use the ns prefix in all the selectors you can also remove the namespace upfront when parsing the xml. eg:
string ns = "http://www.lge.com/ddc";
XDocument xdoc = XDocument.Parse(xml.Replace(ns, string.Empty));
foreach (XElement element in xdoc.Descendants("nationalList")
...
You're not including the namespace, which is "http://www.lge.com/ddc"
, defaulted from the parent element:
XNamespace ns = "http://www.lge.com/ddc";
foreach (XElement element in xdoc.Descendants(ns + "nationalList"))
{
...
}