0

I need to send xml response to a front end application (.NET). The xml response will contain too many tags for data. Basically, I need to send data retrieved from one table which is very large (like one hundred thousand rows or larger). The xml (for example) is like this,

<Values>
   <value>
      <value1></value1>
      <value2></value2>
      .
      .
      <valuen></valuen>
   </value>
   .
   .
<Values>

I am curious about the performance problem. Is there any other alternative approach I should use to improve speed? I am using Freemarker API for xml response.

PS. Please note that Value1, Value2 is only example tag. Actually, they are fields from one table.

user816119
  • 49
  • 1
  • 4
  • 1
    Is it too slow creating the XML or consuming it? Are you sure that it's Freemarker that's the slowdown, and not pulling from the DB? Does it pull from the database once or per-value? Do you have any flexibility in the format of the xml? – Roy Truelove Apr 09 '12 at 20:41
  • No Roy. Actually, I am going to implement like above. Before development, I just want to ask, is my approach is correct or any other good approach should I go. Secondly, I will fetch all date from database once, and then prepare xml template after that. – user816119 Apr 10 '12 at 05:26

2 Answers2

0

There are few things you could do, but from the question and your comments, it's not clear to me where you have wiggle room. Some options:

  1. If you don't have to, don't use XML. XML generation and parsing is relatively slow. If you own your producer and your consumer, use something fast like protocol buffers.

  2. Try some alternatives to Freemarker to create your XML.

A side note that I don't believe will speed you up but it will make things cleaner - don't put the number in the value element. If you don't need to order / ID your elements at all, then your XML should look like this:

<values>
   <value>...</value>
   <value>...</value>
   <value>...</value>
<values>

But if they do need some kind of ID, I recommend this instead:

<values>
    <value id="1">...</value>
    <value id="2">...</value>
    <value id="3">...</value>
</values>
Community
  • 1
  • 1
Roy Truelove
  • 22,016
  • 18
  • 111
  • 153
  • Thanks for your answer. But I thiink i could not clear the question. tag like .... is just an example. There will be many fields from one table like around 120 approxmitaly. Secondly, these will be repeative under tag. I am just curious is that ok I will send this large xml to client application. – user816119 Apr 10 '12 at 16:19
0

I can suggest 2 alternatives:

  1. shorten tag names in your XML like this:

      <Vs>
    
      <v>
    
      <v1></value1>
    
      <v2></value2>
    
      <vn></valuen>
    
      </v>       
    
      <Vs>
    
  2. use JSON instead of XML so you save the tag names completely.

adranale
  • 2,835
  • 1
  • 21
  • 39