Convert xml to json with C#

xml

#1

While converting XML to JSON using c#, By providing the data within the class,I’m getting the output.I need to fetch data from file present in folder .Could anyone please help on this

using Newtonsoft.Json;
using System;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(" <Student>\r\n    <Student_Name>Preethi</Student_Name>\r\n    <SSN>45679</SSN>\r\n    <Course>Electronics and communication</Course>\r\n    <Address>\r\n      <Line_1>#1, 6th cross</Line_1>\r\n      <Line_2>Victoria Layout</Line_2>\r\n      <City>Bangalore</City>\r\n      <Country>India</Country>\r\n    </Address>\r\n  </Student>\r\n</Root>");
        string jsonText = JsonConvert.SerializeXmlNode(doc);
        //Console.WriteLine(jsonText);
        MessageBox.Show(jsonText);
    }
}

}


#2

I don’t see a question or a description of what is stopping you, hard to tell what you want.


#3

how to give the local directory path to fetch xml file


#4

Are you asking about the current working directory of your process or about how to open some kind of dialogue for a user to select a directory? Or something else entirely perhaps?


#5

I want to list the files present in azure blob.
Store this list of files into a array.
My xml to json converter should be able fetch the xml file one after the other and convert it into json.
This json output must be saved back to azure blob.
How can i do this?