Torna al Thread
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.LoadXml("<Root><Element attr1=\"pippo\">ElementValue</Element></Root>");
//Restituisce il primo tag element in qualunque posizione del grafo
System.Xml.XmlNode n = xml.SelectSingleNode("//Element");
//oppure tutti quelli trovati in un array
System.Xml.XmlNodeList narr = xml.SelectNodes("//Element");
//attr1
System.Xml.XmlNode a = n.Attributes.GetNamedItem("attr1");
string attr1Value = a.Value;
a.Value = "nuovo valore!!";
//Element
string elementValue = n.InnerText;
n.InnerText = "nuovo valore elemento!!!";
//Ricerca con un xpath preciso.
System.Xml.XmlNode n2 = xml.SelectSingleNode("/Root/Element");
//Ricerca con un xpath preciso, in un xml con XSD
System.Xml.XmlNode n3 = xml.SelectSingleNode("/*[local-name()='Root']/*[local-name()='Element']");
Console.WriteLine(xml.OuterXml);