[ 7 posts ]

Roman Hoyenko

  • Username: hoyenko
  • Joined: Wed Dec 02, 2009 1:09 pm
  • Posts: 30
  • GitHub: Romario
  • Gists: Romario
  • Offline
  • Profile

Load column names from metadata about table

Post Posted: Tue Jan 05, 2010 2:53 pm
+0-
I am creating reporting system based on the yui DataSource/DataTable.

I will be reading report files from xml, each xml has a metadata section, something like this:

Code:
<ColumnList>
   <column>
      <name>Column1</name>
      <label>Descriptive Label</label>
      <resizeable>true</resizeable>
      <sortable>true</sortable>
      <type>date</type>
      <width>50</width>
   </column>
   <column>
      <name>Column2</name>
      <label>Descriptive Label 2</label>
      <resizeable>true</resizeable>
      <sortable>true</sortable>
      <type>number</type>
      <width>70</width>
   </column>
</ColumnList>


I then want to read the data from the same xml and display it in the table. Is there a way to do it with YUI - all the examples that I saw were using predefined columns.

What would be the best approach here?

Roman Hoyenko

  • Username: hoyenko
  • Joined: Wed Dec 02, 2009 1:09 pm
  • Posts: 30
  • GitHub: Romario
  • Gists: Romario
  • Offline
  • Profile

Re: Load column names from metadata about table

Post Posted: Tue Jan 05, 2010 3:12 pm
+0-
Just found this:

http://www.satyam.com.ar/yui/dt_serverdriven.html

looks like I need to read xml on server side and pass back jason object or something along those lines.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Load column names from metadata about table

Post Posted: Wed Jan 06, 2010 1:00 am
+0-
That example is old and it might not be what you are looking for because it is further complicated by paging and sorting.

You would first use the asyncRequest method of Connection Manager to read your XML. Then you have to parse your colums definition and there is nothing much in YUI that can help you do that, you will have to use the regular XML DOM methods to go through it and build your columns definitions as you parse the data from the definition.

If your server could send the data in JSON format, this part would be much easier as using the YUI JSON parser would allow you to turn the incoming information into regular JavaScript objects and arrays and it would make it easier for you to parse.

In parallel with creating the column defs, you would have to create the responseSchema.fields array for the DataSource. Once the columns and fields definitions are created you would create a LocalDataSource instance passing it a reference to the XML node where the data records actually start.

The example you mention does this but it is further complicated because of the paging and sorting stuff while, on the other hand is simpler because the data comes in JSON and so it does not require you to use the XML DOM methods.

Roman Hoyenko

  • Username: hoyenko
  • Joined: Wed Dec 02, 2009 1:09 pm
  • Posts: 30
  • GitHub: Romario
  • Gists: Romario
  • Offline
  • Profile

Re: Load column names from metadata about table

Post Posted: Wed Jan 06, 2010 7:41 am
+0-
thanks for the quick answer, Satyam, that is what I am doing actually - I parsed the XML on the server side and created JSON objects for column definitions and field definitions.

One question I have is how to better handle the data - right now I pass the JSON meta data (columns and fields) but the data itself goes in XML format. I then use XPATH to get the data.

Do you have an idea how CPU intensive it is compared to having JSON data from the server?
If it is going to take a lot of time to process XML on the client I might convert it to JSON on the server.

My main client is IE6 unfortunately, so it is slow.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: Load column names from metadata about table

Post Posted: Wed Jan 06, 2010 8:09 am
+0-
I am doubtful that you parsed XML and created JSON objects, what you probably did is that you created a series of JavaScript objects. JSON is a data format to represent data on a string.

I am quite sure that JSON should be faster on the client side and would consume much less memory, but I have no solid data for that, after all, decoding it, after doing the safety checks, is nothing more than running the interpreter on it and from then on you are working with plain JavaScript objects, not calling the XML DOM library for every step you want to take.

Googling for JSON vs XML provides plenty of links to articles discussing this.

Roman Hoyenko

  • Username: hoyenko
  • Joined: Wed Dec 02, 2009 1:09 pm
  • Posts: 30
  • GitHub: Romario
  • Gists: Romario
  • Offline
  • Profile
Tags:

Re: Load column names from metadata about table

Post Posted: Wed Jan 06, 2010 8:45 am
+0-
Satyam wrote:
I am doubtful that you parsed XML and created JSON objects, what you probably did is that you created a series of JavaScript objects. JSON is a data format to represent data on a string.

Well, I created JSON string answer in JSP that I evaluated into JavaScript objects.

Quote:
I am quite sure that JSON should be faster on the client side and would consume much less memory, but I have no solid data for that, after all, decoding it, after doing the safety checks, is nothing more than running the interpreter on it and from then on you are working with plain JavaScript objects, not calling the XML DOM library for every step you want to take.

Googling for JSON vs XML provides plenty of links to articles discussing this.


I think I will need to compare to see how fast is it on the big data files.
Thanks for the help!

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Load column names from metadata about table

Post Posted: Wed Jan 06, 2010 11:08 am
+0-
You did the conversion on the server side? I thought you did it on the client side. Then you did, sorry. Check the www.json.org site to look for libraries that do the conversion for you. Converting to JSON is not so trivial, specially if you find umlauts and diacritical marks, which I believe you would find.

On the client side, don't eval() json to conver. Use the YUI JSON utility. If what you display in your tables is data that your visitors would have entered, if they enter as their last name
";alert("hello world!");"
that might get to your execute if you simply eval the data. The JSON utility will not execute that code injection.
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum