Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML String
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Web Services
Titre:
Divers
Thread ID:
00868374
Message ID:
00868611
Vues:
12
Hi Rodolfo,

Besides the excellent tips from Alex, I have decided to translate the answer from the Portuguese VFP forum:

I think that optimizing the XML structure is worth just in case if, in a practical situation, it is really necessary.

The cost we have when working with XML documents is usually associated with their handling and not quite with their transmission. The network hardware compression is also useful, although we developers don't even concern about that...

Anyway, here are some suggestions:

1) If the document is huge, consider using a compression library to transmit it. So you won't have to send the original XML string over the wire;

2) Always prefer attributes to elements when possible. Even though the two documents bellow use the same name to all nodes, if we consider each character taking 1 byte, the first one will take 120 bytes and the second 78 bytes (a saving of about 40%);
<Clientes>
  <Cliente>
    <ID>1000</ID>
    <Nome>Rodolfo</Nome>
    <Sobrenome>Duarte</Sobrenome>
  <Cliente>
<Clientes>
<Clientes>
  <Cliente ID="1000 Nome="Rodolfo" Sobrenome="Duarte" />
<Clientes>
Multiply that by a document which is keeping the data from hundreds of customers and you will see that things start getting interesting. If you are going to transmit only some few customer records, so, IMHO, there is no big difference - I guess the SPAMs I get per minute take more bandwidth <g>

3) Take care with the encoding in which the documents are serialized to. The Latin-ANSI (ISO-8859-1) encoding takes 1 byte per character. UTF-16, on the other hand, takes at least 2 bytes per character and UTF-8 takes 1 byte per non-extended character and two or more bytes per extended character. Making a fast calculation, we can see that the fist document above would take 120 bytes if it were enconded in ISO-8859-1 and 240 bytes (the double) if the UTF-16 encoding were used (bad, isn't it?)

4) Another alternative (weird but still viable) is to create entity references in your documents. Something like the #DEFINEs in VFP. This works if you want to replace complete elements that occur a number of times into the document. A document like this, for example:
<Documento>
  <Estado>Rio Grande do Sul</Estado>
  <Estado>Sao Paulo</Estado>
  <Estado>Rio de Janeiro</Estado>
  <Estado>Rio Grande do Sul</Estado>
  <Estado>Sao Paulo</Estado>
  <Estado>Rio de Janeiro</Estado>
  <Estado>Rio Grande do Sul</Estado>
  <Estado>Sao Paulo</Estado>
  <Estado>Rio de Janeiro</Estado>
</Documento>
Could be written like this:
<!DOCTYPE Documento [
<!ENTITY RS "<Estado>Rio Grande do Sul</Estado>">
<!ENTITY SP "<Estado>Sao Paulo</Estado>">
<!ENTITY RJ "<Estado>Rio de Janeiro</Estado>">
]>
<Documento>
  &RS;&SP;&RJ;&RS;&SP;&RJ;&RS;&SP;&RJ;
</Documento>
Try to make a test: save each of the documents above into a file and try to open them with your Internet browser. You will se that both are presented the same way.

Um abraço!
-----
Fabio Vazquez
http://www.fabiovazquez.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform