I want to read two elements which are siblings, please suggest me appropriate way to do it using XmlReader in C#
Here is my XML
<loginReturn>
<canumber>100556369</canumber>
<emailid>[email protected]</emailid>
<firstname>abc</firstname>
<lastname>abc</lastname>
<masterca/>
<message>Login succesful !</message>
<meternumber>8683169</meternumber>
<mobilenumber>1111111111</mobilenumber>
<status>1</status>
<subca/>
<username>abcbbb</username>
</loginReturn>
I want to read "Status" first and if its not equal to "1" then read "message"...
Here is my code:
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
string msg = Strings.SUCCESS;
reader.ReadToFollowing("status");
var x = reader.ReadElementContentAsInt();
if (x != 1)
{
reader.ReadToFollowing("message");
msg = reader.ReadElementContentAsString();
}
return msg;
}