How to get the attribute value of a XML node using XPath

asterix23

New Member
This is my script, but it only prints spaces in the console. Can someone explain how I can get the attribute values from a XML file using xPath?\[code\] XPathNavigator nav; XPathDocument docNav; XPathNodeIterator NodeIter; XmlNamespaceManager ns; Int32 elementCount; String windowName; private void Form1_Load(object sender, EventArgs e) { docNav = new XPathDocument("C:/BlueEyeMacro/DaMaGeX/Applications/WindowBuilder/GUI.xml"); nav = docNav.CreateNavigator(); ns = new XmlNamespaceManager(nav.NameTable); elementCount = nav.Select("/GUI/window").Count; Console.WriteLine(elementCount); for (int i = 1; i <= elementCount; i++) { NodeIter = nav.Select("/GUI/window[@ID="+i+"]"); windowName = NodeIter.Current.GetAttribute("name", ns.DefaultNamespace); Console.WriteLine("{0}", windowName); } }}\[/code\]XML File
\[code\]<GUI>\[/code\]
\[code\]<window ID="1" name="mainWindow" parent="0" type="0" text="My first window" options="Option 1;" actions="action 1;" exit="exit;" />\[/code\]
\[code\]<window ID="2" name="secondWindow" parent="0" type="0" text="My second window" options="Option 1;" actions="action 1;" exit="exit;" />\[/code\]
\[code\]<window ID="3" name="thirdWindow" parent="0" type="0" text="My third window" options="Option 1;" actions="action 1;" exit="exit;" />\[/code\]
\[code\]</GUI>\[/code\]
 
Back
Top