I have XLM that looks like that (length 278 characters):
<AppList>
<App>
<Info1>Value 1</Info1>
<Info2>Value 2</Info2>
<Info3>Value 3</Info3>
<AppList>
<App>
<Info1>Value 4</Info1>
<Info2>Value 5</Info2>
<Info3>Value 6</Info3>
</App>
</AppList>
</App>
</AppList>
For storing in DB I want it to look like that (length 192 characters):
<AppList><App><Info1>Value 1</Info1><Info2>Value 2</Info2><Info3>Value 3</Info3><AppList><App><Info1>Value 4</Info1><Info2>Value 5</Info2><Info3>Value 6</Info3></App></AppList></App></AppList>
In Notepad++ they have something like Linearize XML
, which does the work.
Is there any way to do that programmatically in C#?
You can consider below methods.
With reference to the duplicated content, you can do it in C#.
Just Compress text-to-text: there's several methods to compress texts. Of course, it is hard to do string search afterwards.
Use XML support in SQL: most of SQL database stores XML in compressed manner natively. Or this article could be helpful also.
Describe in Json: XML is verbose than json expression in general. XML and json both are tree structure so 1:1 conversion is possible.