I have stored the xml structure into a string abcd.
string abcd="<xmlstruct>
<test>
<name>testname</name>
<address>testaddress</address>
<subject>testsub<subject>
</test>
<test1>
<name>testname1</name>
<address>testaddress1</address>
<subject>testsub<subject>
</test1>
<test2>
<name>testname2</name>
<address>testaddress2</address>
<subject>testsub2<subject>
</test2>
<test3>
<name>testname3</name>
<address>testaddress3</address>
<subject>testsub3<subject>
</test3>
</xmlstruct>";
I retrieved the xml values from the string like,
var xElem = XElement.Parse(abcd);
string getname = xElem.Element("test").Element("name").Value;
string getname1 = xElem.Element("test1").Element("name").Value;
string getname2 = xElem.Element("test2").Element("name").Value;
string getname3 = xElem.Element("test3").Element("name").Value;
It was working fine.My question is,“Is there any possible way to make the loop and get the test,test1,test2,test3 values?”
Your choice for
"test0"is a bit irregular but this should do it:But you probably should look into a better XML structure, something like