how do i get a node position in an xml file
-
im trying to make an xml search method for example this is my xml file what i wanna do its get movinh trought the xml and when i get the looking for attribute the method will give me back an string with this caracteristics d=0&n=1 where d its equal to the current node and n its equal to the current item node where the looking attribute was found for example d=0&n=1 the atribute nombre = calendario but if i im on a child of a item node for example the result it will be d=1&n=0,0 please if some one can helpme plese email me quickly
-
im trying to make an xml search method for example this is my xml file what i wanna do its get movinh trought the xml and when i get the looking for attribute the method will give me back an string with this caracteristics d=0&n=1 where d its equal to the current node and n its equal to the current item node where the looking attribute was found for example d=0&n=1 the atribute nombre = calendario but if i im on a child of a item node for example the result it will be d=1&n=0,0 please if some one can helpme plese email me quickly
-
Try checking the "Do not treat <'s as HTML tags" checkbox so we can actually read your xml... mav
-
Try checking the "Do not treat <'s as HTML tags" checkbox so we can actually read your xml... mav
-
private string DumpIndex(XmlNode node) { string sAns = ""; if (node.ParentNode != null) { int iPos = -1; foreach (XmlNode c_Node in node.ParentNode.ChildNodes) { iPos++; if (c_Node.Equals(node)) { sAns = this.DumpIndex(node.ParentNode); if (sAns.Length > 0) sAns += "."; sAns += iPos; break; } } } return sAns; }
-
private string DumpIndex(XmlNode node) { string sAns = ""; if (node.ParentNode != null) { int iPos = -1; foreach (XmlNode c_Node in node.ParentNode.ChildNodes) { iPos++; if (c_Node.Equals(node)) { sAns = this.DumpIndex(node.ParentNode); if (sAns.Length > 0) sAns += "."; sAns += iPos; break; } } } return sAns; }
-
i think that the code its perfect but can u explainme how do i know what node i must send to this funtion first for examle string dumindex(myfirsnode)
using System.Xml; XmlDocument c_Doc = new XmlDocument(); c_Doc.Load(...) or LoadXml(...); XmlNodeList c_List = c_Doc.DocumentElement.SelectNodes("//*[nombre='???']"); ... or ... c_Doc.DocumentElement.SelectNodes("//item[nombre='???']"); foreach (XmlNode c_Node in c_List) { ... Do the DumpIndex with c_Node and whatever else ... } I am writing this away from my computer, so I cannot check it. Use the first SelectNodes methods to include all nodes, the second if you want to include only the item nodes. Of ccource the ??? needs to be replaced with the name that you are searching for. Anyway, you should be able to get the idea on how to use XPath (If you need to learn more, check the w3schools.com site)