string fileName = "yourfilePath"; string nodeList = "//string-array/item"; string itemInnerText = "Item 1"; string attributeName = "Id"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); XmlNodeList xmlNodeList = xmlDoc.SelectNodes(nodeList); foreach(XmlNode node in xmlNodeList) { if (node.Item(0).InnerText == itemInnerText) return node.Attributes[attributeName].Value; }
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("path to xml file"); XmlNodeList gradientNodeList = xmlDoc.SelectNodes("//gradient"); foreach(XmlNode gradient in gradientNodeList){ string startColor = gradient.Attributes["android:startColor"].Value; //GET gradient.Attributes["android:startColor"].Value = "#FFF"; //SET Custom Value } //OR Simply XmlNode xn = xmlDoc.SelectSingleNode("/shape/gradient"); //and same as above
public static List<XmlValue> GetAllOrg() { XmlDocument document = new XmlDocument(); document.Load(strXmlPath); XmlNodeList nodeList = document.SelectNodes("Organizations/Organization"); List<XmlValue > list = new List<XmlValue >(); foreach (XmlNode node in nodeList) { list.Add(new XmnValue(){ value = node.Attributes["name"].Value, name = node.Attributes["name"].Name }); } return list; }
Console.WriteLine("XPathDocument:"); XPathDocument xpathDoc = new XPathDocument("../../XMLFile4.xml"); foreach (XPathNavigator nav in xpathDoc.CreateNavigator().Select("//namespace::*")) { Console.WriteLine("Node type: {0}; name: {1}; value: {2}.", nav.NodeType, nav.Name, nav.Value); } Console.WriteLine(); Console.WriteLine("DOM XmlDocument:"); XmlDocument doc = new XmlDocument(); doc.Load("../../XMLFile4.xml"); foreach (XmlNode node in doc.SelectNodes("//namespace::*")) { Console.WriteLine("Node type: {0}; name: {1}; value: {2}.", node.NodeType, node.Name, node.Value); } Console.WriteLine(); Console.WriteLine("MSXML 6 DOM:"); dynamic msxmlDoc = Activator.CreateInstance(Type.GetTypeFromProgID("Msxml2.DOMDocument.6.0")); msxmlDoc.load("../../XMLFile4.xml"); foreach (dynamic node in msxmlDoc.selectNodes("//namespace::*")) { Console.WriteLine("Node type: {0}; name: {1}; value: {2}.", node.nodeType, node.name, node.nodeValue); }
doc.Load(file); XmlNodeList nodes = doc.SelectNodes("//data");
outDoc.AppendChild(resElem); XmlNodeList stringNodes = inDoc.SelectNodes("root/data"); foreach (XmlNode n in stringNodes)