I\'m trying to query out some information from a heavily namespaced XML document and am having some trouble finding attributes that are also namespaced.
The XML looks li
using Linq to xml
XNamespace skos = XNamespace.Get("http://www.w3.org/2004/02/skos/core#");
XNamespace geo = XNamespace.Get("http://www.geonames.org/ontology#");
XNamespace rdfs = XNamespace.Get("http://www.w3.org/2000/01/rdf-schema#");
XDocument rdf = XDocument.Load(new StringReader(xmlstr));
foreach(var country in rdf.Descendants(geo + "Country"))
{
Console.WriteLine(
country.Attribute(skos + "notation").Value + " " +
country.Attribute(rdfs + "label").Value );
}
You can use System.Linq:
country.Attributes().Where(a => a.Name.LocalName == "notation")?.First()?.Value;