In the following XML file, i try to save in a list all the id attributes:
<?xml version="1.0"?>
<PressReleases>
<PressRelease id="545" version="1">
<Name>Convert number to string</Name>
<Date>20/05/1985</Date>
<Input>1</Input>
<Output>One</Output>
</PressRelease>
<PressRelease id="544" version="1">
<Name>Find succeeding characters</Name>
<Date>19/05/1985</Date>
<Input>abc</Input>
<Output>def</Output>
</PressRelease>
<PressRelease id="543" version="1">
<Name>Convert multiple numbers to strings</Name>
<Date>17/05/1985</Date>
<Input>123</Input>
<Output>One Two Three</Output>
</PressRelease>
<PressRelease id="542" version="1">
<Name>Find correlated key</Name>
<Date>02/05/1985</Date>
<Input>a1</Input>
<Output>b1</Output>
</PressRelease>
<PressRelease id="541" version="1">
<Name>Count characters</Name>
<Date>04/02/1985</Date>
<Input>This is a test</Input>
<Output>14</Output>
</PressRelease>
<PressRelease id="540" version="1">
<Name>Another Test</Name>
<Date>09/01/1985</Date>
<Input>Test Input</Input>
<Output>10</Output>
</PressRelease>
</PressReleases>
This block of code saves only the first Id written in the first Press Release node (545). I need all of them (545,544 ect)
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\Users\ARNAUDR\Desktop\test.xml");
//string xmlcontents = doc.InnerXml;
XmlNodeList xnList = doc.SelectNodes("/PressReleases");
List<int> IDsInDistantXML = new List<int>();
foreach (XmlNode xn in xnList)
{
XmlNode PressRelease = xn.SelectSingleNode("PressRelease");
if (PressRelease != null)
{
IDsInDistantXML.Add(Convert.ToInt16(PressRelease.Attributes["id"].Value));
}
}
Thanks in advance for your help