|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple xpath questionsupposed I have xml file <a> <b> <name>ggg</name> <c>10</c> <name>ddd</name> </b> <b> <name>zzz</name> <c>10</c> <name>yyyy</name> </b> <b> <name>zzz</name> <c>12</c> <name>xxxxx</name> </b> </a> Lets say I need to select all nodes where c=10 and print a path of names dim my_list as xmlnodelist =myRootNode.SelectNodes("//a/b[c='10']") Now I need to print a path of nodes name. The result should be: --------------------- ggg/ddd zzz/yyy -------------------- Please help me. How can I do that? I have no idea how to get this info from my_list Sorry, error in xml file. Should be:
<root> <a> <name>ddd</name> <b> <name>ggg</name> <c>10</c> </b> </a> <a> <name>yyyy</name> <b> <name>zzz</name> <c>10</c> </b> </a> <a> <name>zzz</name> <b> <c>12</c> <name>xxxxx</name> </b> </a> </root> Something like (C# - and I've been lazy using string concatenation):
XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); foreach (XmlElement el in doc.SelectNodes("/root/a/b[c='10']")) { string name = el.SelectSingleNode("name").InnerText, path = ""; foreach (XmlElement pathEl in el.SelectNodes("ancestor-or-self::*/name")) { path += "/" + pathEl.InnerText; } Debug.WriteLine(name + ": " + path); } Marc Thanks just what I needed
Show quoteHide quote "Marc Gravell" <marc.grav***@gmail.com> schrieb im Newsbeitrag news:%23gPaq0ktGHA.3964@TK2MSFTNGP04.phx.gbl... > Something like (C# - and I've been lazy using string concatenation): > > XmlDocument doc = new XmlDocument(); > doc.LoadXml(xml); > foreach (XmlElement el in doc.SelectNodes("/root/a/b[c='10']")) > { > string name = el.SelectSingleNode("name").InnerText, path = ""; > foreach (XmlElement pathEl in > el.SelectNodes("ancestor-or-self::*/name")) > { > path += "/" + pathEl.InnerText; > } > Debug.WriteLine(name + ": " + path); > } > > Marc >
Unique an array of strings
problems with compacting Directly Passing Variables Publish Version number Adding Help To My Application *** Using DataReaders to populate combo boxes - please help!!! *** How to remove last line in a file Monitor Software Installation Changes DirectCast Timeout issue HttpWebResponse ClickOnce question |
|||||||||||||||||||||||