Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get InnerText from Collection

Is there a way to get the innertext of a node when the node is inside a collection Currently i have this

Collection<string> DependentNodes = new Collection<string>();
foreach (XmlNode node in nodes)
{
  for (int i = 0; i < node.ChildNodes.Count; i++)
  {
    DependentNodes.Add(node.ChildNodes[i].InnerXml);
    //the reason i'm using InnerXml is that it will return all the child node of  testfixture in one single line,then we can find the category & check if there's dependson
   }
}
    string selectedtestcase = "abc_somewords";
    foreach (string s in DependentNodes)
     {
      if(s.Contains(selectedtestcase))
       {
        MessageBox.Show("aaa");
       }

     }

When i debug string s or the index has this inside of it[in a single line]

<testfixture name="1" description="a">
  <categories>
    <category>abc_somewords</category>
  </categories>
  <test name="a" description="a">
    <dependencies>
      <dependson typename="dependsonthis" />
    </dependencies>
  </test>
</testfixture>

What i'm trying to do is when we reach "testfixture 1" it will find "abc_somewords" & search the "dependson typename"node(if any) and get the "typename"(which is "dependonthis").

like image 861
someguy Avatar asked Dec 09 '25 10:12

someguy


1 Answers

Could you use linq to xml. Something like the below might be a decent start

xml.Elements("categories").Where(x => x.Element("category").Value.Contains(selectedtestcase));

This is off the top of my head so might will need refining

P.S. Use XElement.Load or XElement.Parse to get your xml into XElements

like image 80
NinjaNye Avatar answered Dec 12 '25 00:12

NinjaNye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!