Reading XML Document using XML Reader C#
StringBuilder myresult = new StringBuilder(); Dictionary myHeader = new Dictionary();
string response1 =
XmlReader xRead = XmlReader.Create(new System.IO.StringReader(response1));
XmlReader result = xRead;
public string processXMLTextReader(XmlReader xRead, String element)
{
value = "";
try
{
while (xRead.Read())
{
if (xRead.NodeType == XmlNodeType.Element)
{
if (xRead.Name == element)
{
value = xRead.GetAttribute("AccountNo").ToString();
break;
}
}
}
}
catch (Exception e)
{
value = e.Message;
}
return value;
}
Sample 2:
public Dictionary(int,string) processReader(XmlReader xRead, String element){
xRead.ReadToFollowing(element);
xRead.MoveToFirstAttribute();
Dictionary(int,string) mydict = new Dictionary
for (int i = 0; i < xRead.AttributeCount; i++)
{
//string genre = .ToString();
mydict.Add(i, xRead.GetAttribute(i));
}return mydict;
}
reading Response:
//the below method call returns result in XML format string response = ConfirmMuncipality(mRequest);
XmlReader xReadx = XmlReader.Create(new System.IO.StringReader(response(OR)(Response1)));
XmlReader resultb = xReadb;
myHeader = new Dictionary
myHeader = syntelTest.processReader(resultx, "ns0:ConfirmPaymentItems");
if (myHeader.Count == 1)
{
string AccountNo="";
AccountNo = myHeader[0];
}
No comments:
Post a Comment