How To Convert XML string To String

using System;
using System.Xml;
using System.Collections.Generic;

public class MyClass
{
  public static void Main()
  {
      try
      {
          string str = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<StoredProcedureList>
<StoredProcedure ID = ""usp_get_gpxx"">
<Parameters>
<Name>gpdm</Name>
<Type>char</Type>
</Parameters>
</StoredProcedure >
</StoredProcedureList>";
          XmlTextReader xtr = new XmlTextReader(str, XmlNodeType.Element, null);
          while (xtr.Read())
          {
              if (xtr.Name == "Parameters")
              {
                  xtr.Read();
                  string key = string.Empty;
                  Dictionary<string, string> result = new Dictionary<string, string>();
                  while (xtr.Name != "Parameters")
                  {
                      if (XmlNodeType.Element == xtr.NodeType)
                      {
                          key = xtr.Name;
                      }
                      else if (XmlNodeType.Text == xtr.NodeType)
                      {
                          result.Add(key, xtr.Value);
                      }
                      xtr.Read();
                  }
                  foreach (string k in result.Keys)
                  {
                      Console.WriteLine("{0}:{1}", k, result[k]);
                  }
              }
          }
      }
      catch (Exception e)
      {
          Console.WriteLine(e.ToString());
      }
      finally
      {
          Console.WriteLine("END");
          Console.Read();
      }
  }
}
Reactions

Post a Comment

1 Comments

  1. "catch(Exception e)"...
    it's bad approach...............
    to say the truth it's STUPID approach

    ReplyDelete

Please do not post any spam link in the comment box😊

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)

Close Menu