Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,I want to convert data to json and xml format.Can you help me find these sourece codes at this website. Thanks in advance.
Posted
Comments
AmitGajjar 1-Jun-12 0:39am    
what exactly you want to achieve. can you give us an example ?
yuanhaosh 1-Jun-12 3:10am    
such as i have a set of data,and want to convert to xml,json.
Sandeep Mewara 1-Jun-12 3:05am    
And what have you tried so far?
yuanhaosh 1-Jun-12 3:10am    
such as i have a set of data,and want to convert to xml,json.
Sandeep Mewara 1-Jun-12 3:48am    
I asked what you have TRIED and not what you WANT!

1 solution

Hi,

what you are asking is not clear, but let me give you example. and let me know if this is fit in your scenario.

check below code, it will convert your text file content into xml.
C#
string str = "abc|xyz|pqr";
           string[] strsplit = str.Split('|');

           XDocument xdoc = new XDocument();
           XElement root = new XElement("Root");

           foreach (var item in strsplit)
           {
               root.Add(new XElement("item", item));
           }

           xdoc.Add(root);


Output :(xdoc object content)
XML
<root>
  <item>abc</item>
  <item>xyz</item>
  <item>pqr</item>
</root>


is that fulfill your requirement ?

thanks
-Amit
 
Share this answer
 
v2
Comments
yuanhaosh 1-Jun-12 4:08am    
Thanks a lot.I found a code of xml convert to json,and it's ok.Now the source data is what i am not clear.maybe it's txt.

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