Click here to Skip to main content
14,971,296 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to serialize XML to JSON. Getting the XML from a file location and running it to a foreach statement to serialize. But the thing is the output of the json is
{"Description":"2015 FEBRUARY RENTAL"}
{"LineDescription":"Office Rental - Zero-Rated Sales"}

Here is the XML:
<Description>2015 FEBRUARY RENTAL</Description>
<LineDescription>Office Rental - Zero-Rated Sales</LineDescription></root>

It won't work without the root tag for some reason.
Here is my code:
static void Main(string[] args)
    XElement xEle = XElement.Load(@"D:\Documents\Projects\HeXML\tae.xml");
    IEnumerable<XElement> invoices = xEle.Elements();

    foreach (var invoice in invoices)

I'm sorry. I want to know where I went wrong.
Updated 7-May-15 5:33am
BillWoodruff 7-May-15 12:04pm
Why aren't you de-serializing the XML into an instance of a Class, and then serializing that instance out with JSON ?
Joshua Masa 7-May-15 12:20pm
Sorry, I'm confused.
BillWoodruff 7-May-15 20:58pm
You may wish to try using xsd.exe and compare the result:

1 solution

Have a look at past answer: remotly convert xml to json in mvc[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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