0
I’m making a Webapi that generates an XML, this XML is read several times a day, so in the first run it serializes all my XML and saves it to disk, and during 24h it reads from disk instead of serializing the whole object again.
I do this because it has several accesses, XML are great some with up to 300mb, and information can be cached for 24h
The problem is that the description field, I believe it could be 'compressed' or better could try to make a Minify in xml before burning it to disk. I’m trying to remove the whitespace and line breaks just from that field for now so I already reduce some good megas.
Using Webapi in C#, Redis, MSSQL
Today I’m sending her like this:
<description><![CDATA[SOBRADO
Área Terreno: 8 x 28
Área Construída: 170m²
Pavimento Superior:
2 dormitórios sendo 1 dormitorio com armario embutido planejado e um maste
banheiro
jardim de inverno
sacada
Pavimento Térreo:
2 salas
Copa
Cozinha
Corredor lateral
jardim na frente
quintal
Edícula:
1 dormitórios
banheiro
lavanderia
deposito
4 vagas
IPTU R$ 1.200,00 anual]]></description>
I would like to send so:
<description><![CDATA[SOBRADO Área Terreno: 8 x 28 Área Construída: 170m²...
I use 2 functions to try to clear the code, but it is not as you would like.
description = Biblioteca.RemoveTroublesomeCharacters(Biblioteca.CorrigeDescricao(imovel.Descricao)),
internal static string CorrigeDescricao(string descricao)
{
var tab = '\u0009';
descricao = descricao.Replace(" ", " ");
descricao = descricao.Replace("=\r\n", "");
descricao = descricao.Replace(";\r\n", "");
descricao = descricao.Replace("\t", " ");
descricao = descricao.Replace(tab.ToString(), "");
return RemoveHtml(descricao);
}
And
internal static string RemoveTroublesomeCharacters(string inString)
{
if (inString == null) return null;
var newString = new StringBuilder();
char ch;
for (int i = 0; i < inString.Length; i++)
{
ch = inString[i];
// remove any characters outside the valid UTF-8 range as well as all control characters
// except tabs and new lines
//if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n' || ch == '\r')
//if using .NET version prior to 4, use above logic
if (XmlConvert.IsXmlChar(ch)) //this method is new in .NET 4
{
newString.Append(ch);
}
}
return newString.ToString();
}
And what’s your problem?
– Maniero
want to remove whitespace, line breaks try to minify the file, some has 300mb if I manage to remove some characters can already mean some 20mb at the end
– Dorathoto
@Dorathoto, what kind of application will consume your service? all are . NET?
– Tobias Mesquita
no, most of them I think are in java.. but I don’t know their technologies.
– Dorathoto