There is an xml file:

 <result> <response> <code>200</code> </response> <tracks> <track id="XXXXXXXX"> <code>402</code> </track> </tracks> <geo></geo> </result> 

You need to get a variable of type string in which the value of the " тега "

 result=>code=>tracks=>track id="XXXXXXXX"=>code 

That is, 402 .

I could only upload xml :

 XDocument Info = XDocument.Load("http://xxx.xx/id=" + textBox1.Text); 

The value of the textBox 'and in this case XXXXXXXX

    2 answers 2

    (Article on CodeProject , which you planted - not very :)

    • Specifically for your case it is worth more actively to use Descendants .

    • Here is the code of the all-in-one test case for your xml'ки , when you implement something like this, then carefully check the possibility of returning an empty collection by any of the methods.

    • That is, if the Descendants() method allows an empty collection as arguments (see the fifth Assert.Equal above), then when you start working with individual arguments, getting a NullReferenceException quite simple.

       [Fact] public void CanParseCustomXmlFile() { const string xmlString = @"<result> + <response> <code>200</code> </response> <tracks> <track id=""12345""> <code>402</code> </track> </tracks> <geo></geo> </result>"; var document = XDocument.Parse(xmlString); Assert.Equal(1, document.Descendants("result").Count()); Assert.Equal(2, document.Descendants("code").Count()); Assert.Equal(1, document.Descendants("track").Count()); Assert.Equal(1, document.Descendants("track").Descendants("code").Count()); Assert.Equal(0, document.Descendants("dwdwdq23423fxwdqwd") .Descendants("code").Count()); var trackNodes = document.Descendants("track"); var trackNodesWithId = trackNodes.Where( trackNode => trackNode.Attribute("id") != null); var trackNode12345 = trackNodesWithId.Where( trackNode => trackNode.Attribute("id").Value == "12345"); Assert.NotNull(trackNode12345); Assert.Equal(1, trackNode12345.Descendants("code").Count()); Assert.Equal("402", trackNode12345.Descendants("code").First().Value); } 

      Here it is. Should help!