1

How i can get following XML data to easy understand format.

Input XML Data

<?xml version="1.0"?>
<user>
<details><name>xyz</name><class>mno</class><city>pqr</city></details>
<info><id>321</id><code>654</code></info>
</user>

Expected Output

<?xml version="1.0"?>
<user>
    <details>
        <name>xyz</name>
        <class>mno</class>
        <city>pqr</city>
    </details>
    <info>
        <id>321</id>
        <code>654</code>
    </info>
</user>

Anyone idea how to do this using HTML,JQuery and C#.

Thank you

3
  • You want to format the data in display in the UI? Commented Jul 5, 2017 at 10:56
  • Yes Mr. Chetan Ranpariya Commented Jul 5, 2017 at 11:07
  • And what code you have written for this? Commented Jul 5, 2017 at 11:12

2 Answers 2

1

Try with the below one(With C#).

using System;
using System.IO;
using System.Xml;

namespace FormatXMLStringConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string rawStringXML = "<?xml version='1.0'?><user><details><name>xyz</name><class>mno</class><city>pqr</city></details><info><id>321</id><code>654</code></info></user>";
            XmlDocument xmlDoc = new XmlDocument();
            StringWriter sw = new StringWriter();
            xmlDoc.LoadXml(rawStringXML);
            xmlDoc.Save(sw);
            string formattedXml = sw.ToString();
            Console.WriteLine(formattedXml);
            Console.Read();
        }
    }
}

OUTPUT

enter image description here

Check and let me know if it solves your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad To hear. Welcome :)
1

I got snippet solution for that XElement.Parse(); using linq. Example as follow

string rawStringXML = "<user><details><name><firstname>pradip</firstname><lastname>Talaviya</lastname></name><class>mno</class><city>pqr</city></details><info><id>321</id><code>654</code></info></user>";
XElement message = XElement.Parse(rawStringXML);
Console.WriteLine(message.ToString());
Console.Read();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.