Click here to Skip to main content
15,797,984 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
Hi All,

I am new to xml in .Net Development,

will you please tell me the method through which i can able to parse xml string into key value pair.

my xml string is like given below

   <summary>Application Programming,Database Programming,Application Support and Maintenance</summary>
      <name>xyz limited</name>

thanks in advance
_Asif_ 27-Aug-14 7:35am    
What do you mean by Key value pair?

Use an XmlDocument[^] and call the LoadXml[^] method.
Share this answer
This will help you convert XML to Object
XML Serialization and Deserialization: Part-1[^]
Share this answer
You Can Try this
I have Considered the following Source XML

     <id> 1 </id>
     <title> ABC <title>
     <company> PQR <company>

And Target XML as

Code Goes Here

XmlDocument xDoc =  new XmlDocument();
XmlDocument xDoc2 =  new XmlDocument();

xDoc.Load(HttpContext.Current.Server.MapPath("menu.xml"); // source xml
xDoc2.Load(HttpContext.Current.Server.MapPath("menu1.xml"); // target xml 

XmlNode Page = null;
string[] str = {"id","title","company"} //Your attributes with your logic
XmlNode Data = xDoc2.CreateNode(XmlNodeType.Element,"position",null);

for(int i = 0 ; i < 3 ; i++)
   Page = xDoc.SelectSingleNode("position/" + str[i]);
   XmlAttribute item = xDoc2.CreateAttribute(str[i]);
   item.Value = Page.InnerText;



Your OutPut will be
  <position id=1 title=ABC company=PQR />
Share this answer
Almost everything you need is here[^]

Also noteworthy will be learning about XPathExpressions which would allow you to read and select particular nodes/series of nodes in XML as per your choice.

Would definitely recommend following to get basics of XPath.[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900