Please help me parse this file and get the output as JSON. So far I am able to get the key (name) and Value (value) pair. But I don't understand how to get the array inside this key-value pair. New to XML and JSON and C#. Guru's please help..
<?xml version="1.0" encoding="US-ASCII"?>
<Information>
<first_name>Frank</first_name>
<last_name>Murphy</last_name>
<customer_support_url>google.com</customer_support_url>
<received_date>12/30/2013</received_date>
<customer_support_phone_number>(888)111-2222</customer_support_phone_number>
<employer_name>Google Inc</employer_name>
<label>Dependent Care</label>
<set_flag>0</set_flag>
<employee_id>11111</employee_id>
<employer_id>111</employer_id>
<claim_form_id>1234</claim_form_id>
<employer_url>For more information please go to: <a href=http://google.com>google.com</a></employer_url>
<tax>$1,500.00</tax>
<claim_form_id>1234</claim_form_id>
<claim_details>
<claim_form_id>1234</claim_form_id>
<amount_claimed>100</amount_claimed>
<expense_name>ChildCare</expense_name>
<service_date>2013-06-17</service_date>
<claim_status>Approved</claim_status>
<claim_status_reason/>
</claim_details>
<Location>Dublin</Location>
So far this is what I have done for testing purpose in a console application:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XDocument doc = XDocument.Load("input.xml");
// Declare your token Colelction Class
foreach (var keyvalue in doc.Root.DescendantNodes().OfType<XElement>().Select(x => new XElement("token", new XElement("name", x.Name), new XElement("value", x.Value))))
{
Console.WriteLine(keyvalue);
//Add name,value to token collection
}
// Convert it to json
//return
Console.ReadKey();
}
}
}