I have different xml files and would like to get one specific value from each xml. what i'm trying to do is to search some of the elements in the xml and then when there is specific value or reference, then get the value of this reference. for example one xml has this:
<textInfo>
<freeText>
<informationType>15</informationType>
</freeText>
</textInfo>
<textInfo>
<freeText>
<textSubject>4</textSubject>
<informationType>47</informationType>
</freeText>
<freeText>some text</freeText>
</textInfo>
<textInfo>
<freeText>
<informationType>733</informationType>
<status>1</status>
</freeText>
</textInfo>
other xml has more than that, for example:
<textInfo>
<freeText>
<textSubject>4</textSubject>
<informationType>15</informationType>
<status>0</status>
</freeText>
</textInfo>
<textInfo>
<freeText>
<textSubject>4</textSubject>
<informationType>47</informationType>
</freeText>
<freeText>some text</freeText>
</textInfo>
<textInfo>
<freeText>
<textSubject>4</textSubject>
<status>0</status>
</freeText>
</textInfo>
<textInfo>
<freeText>
<textSubject>4</textSubject>
<informationType>61</informationType>
</freeText>
</textInfo>
<textInfo>
<freeText>
<textSubject>4</textSubject>
<informationType>39</informationType>
</freeText>
<freeText>some text</freeText>
<freeText>some other text</freeText>
</textInfo>
so what i tried to do is to first find the Length and how many tags in the xml and then use Foreach or While and then IF statement where tag equals 39 then get the value of the freeText tag
foreach (search all <textInfo>)
{
if (<informationType> ==39)
{
do get the value of <freeText> of that <informationType>
}
}
my problem is i don't know which to use in this case, should i use Foreach or while. and how to use it.
Note: i'm only getting the xml from webservice. i'm not storing it somewhere or have it as xml file. i'm just handling all the xml in my project and only stuck on this searching multiple tags to find one value
EDIT/update i have tried below two codes but both are returning a Null value
XmlDocument doc = new XmlDocument();
doc.LoadXml(requestInterceptor.LastResponseXML);
foreach (XmlNode node in doc.SelectNodes("//textInfo/freeText[informationType>=39]/informationType"))
{
Object.Type = node.InnerText;
}
other code:
XDocument doc1 = XDocument.Parse(requestInterceptor.LastResponseXML);
var query = doc1.Descendants("textInfo").Where(ft => ((int?)ft.Element("informationType")).Equals("39"));
from c in doc1.Root.Descendants("textInfo")
where (c.Attribute("informationType").Equals("39"))
select c.Element("freeText");
Object.Type = query.ToString();