Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by daniel vanesse on Jan 22, 2008 02:35
open dhtmlx forum
loading a grid from INLINE xml?

would it be possible to load a grid from a INLINE xml object?
Answer posted by Support on Jan 22, 2008 06:01
The grid has possibility to load from XML string
    grid.loadXMLString(" xml as text here ")
And, in case of IE, from XML object embeded in page ( xml island)
    grid.parseXML('id_of_xml_island');
Answer posted by Daniel Vanesse on Jan 22, 2008 06:53

Given the size of the grid (3000 rows or more), it would not fit in a Javascript string which is limited to 64k (unless you know a way to make a javascript string up to 1Mb !!)

Why is not the xml island available with Firefox? That is exactly what we need. Do it and I will by an "Pro" version of dHtmlXGrid immediately!

 

 

Answer posted by Support on Jan 23, 2008 03:50
>> it would not fit in a Javascript string which is limited to 64k
This is limit to js command line , not the string limit. String itself can contain more than 1Mb of data for sure.
You can use next approach

<textarea id="for_xml" style="display:none">
    ... xml of any length here...
</textarea>

<script>
    grid.loadXMLString(document.getElementById('for_xml').value);



>>Why is not the xml island available with Firefox?
I think this is question for FF developers :)
In case of FF , when document with HTML doctype parsed , unknown tags, such as <xml> will be ignored and not included in DOM model
There is no technical problem to use grid.parseXML with any browser, but only IE ( and Safari partially ) allow to embed XML document inside HTML page



Answer posted by daniel vanesse on Jan 23, 2008 08:20

Sorry, Firefox allows embedding xml into a html document (e.g. a data island, a svg , etc...). I have 6000 documents of that kind properly displaying with Firefox.
The bug is in your code and I have found it !!!. Send me an email ( dvanesse@namsa.nato.int ) and agree to give me a "Enterprise" license for free and you will get the solution :-)

Answer posted by Support on Jan 24, 2008 01:32
FireFox can handle XML tag inside HTML content but it use HTML parser against it, in result the data is not usable ( the xpaths used in case of normal xml returns empty result sets in case of XML island in FF )
The code of parseXML really written in the way, which not allow to use XML Islands in FF, but it doesn't matter because even if XML Island objects correctly detected it still not usable.
Answer posted by Daniel Vanesse on Jan 24, 2008 05:21

Here is a very simple example of an inline xml data island properly managed with Firefox + XPath.

Copy the code below to something.html and open it with Firefox.

<html>
<head>
 <title>Test XML data island</title>
</head>

<body>
<div style="visibility: hidden; height:0px;">
<xml id="xmlDataIsland" type="xml/data" > 
<rows>
  <row id="1" attr="John">
  <cell>-1500</cell>
  <cell>A Time to Kill</cell>
  <cell>John Grisham</cell>
  <cell>12.99</cell>
  <cell>1</cell>
  <cell>24</cell>
  <cell>0</cell>
  <cell>05/01/1998</cell>
 </row>
 <row id="2" attr="Bob">
  <cell>1000</cell>
  <cell>Blood and Smoke</cell>
  <cell>Stephen King</cell>
  <cell>0</cell>
  <cell>1</cell>
  <cell>24</cell>
  <cell>0</cell>
  <cell>01/01/2000</cell>
 </row>
 <row id="3" attr="Louis">
  <cell>-200</cell>
  <cell>The Rainmaker</cell>
  <cell>John Grisham</cell>
  <cell>7.99</cell>
  <cell>0</cell>
  <cell>48</cell>
  <cell>0</cell>
  <cell>12/01/2001</cell>
 </row>
 <row id="4" attr="Susy">
  <cell>350</cell>
  <cell>The Green Mile</cell>
  <cell>Stephen King</cell>
  <cell>11.10</cell>
  <cell>1</cell>
  <cell>24</cell>
  <cell>0</cell>
  <cell>01/01/1992</cell>
 </row>
 <row id="5" attr="Dan">
  <cell>700</cell>
  <cell>Misery</cell>
  <cell>Stephen King</cell>
  <cell>7.70</cell>
  <cell>0</cell>
  <cell>na</cell>
  <cell>0</cell>
  <cell>01/01/2003</cell>
 </row>
 <row id="6" attr="Sue">
  <cell>-1200</cell>
  <cell>The Dark Half</cell>
  <cell>Stephen King</cell>
  <cell>0</cell>
  <cell>0</cell>
  <cell>48</cell>
  <cell>0</cell>
  <cell>10/30/1999</cell>
 </row>
 <row id="7" attr="Pat">
  <cell>1500</cell>
  <cell>The Partner</cell>
  <cell>John Grisham</cell>
  <cell>12.99</cell>
  <cell>1</cell>
  <cell>48</cell>
  <cell>1</cell>
  <cell>01/01/2005</cell>
 </row>
 <row id="8" attr="Craig">
  <cell>500</cell>
  <cell>It</cell>
  <cell>Stephen King</cell>
  <cell>9.70</cell>
  <cell>0</cell>
  <cell>na</cell>
  <cell>0</cell>
  <cell>10/15/2001</cell>
 </row>
 <row id="9" attr="Paul">
  <cell>400</cell>
  <cell>Cousin Bette</cell>
  <cell>Honore de Balzac</cell>
  <cell>0</cell>
  <cell>1</cell>
  <cell>1</cell>
  <cell>0</cell>
  <cell>12/01/1991</cell>
 </row>
</rows>
</xml> 
</div>
 

<script>
function displayObj(){
 var i=rowid.value;
 var e=document.getElementById(i);
 var a=e.getAttribute("attr");
 alert(a);
}

function doXpath()
{
 var arg=xp.value;
 var col = document.evaluate(arg, document.getElementById("xmlDataIsland"), null, XPathResult.ANY_TYPE, null);
 alert(col);
      var colMemb = col.iterateNext();
 var i=0;
      while (colMemb)
      {   
    i++;
         colMemb = col.iterateNext();
      }
 alert("The collection has " + i + " members");
      ;
}
</script>
<p align="left">


Enter a number (1 to 9) to select the corresponding xml element 'attr' attribute
<br><br>
<input type="text" name="rowid" id="rowid" maxlength="1" value="1"/>
<input type="button" onclick="displayObj()" value="click to display the result"/>
<br><br><br><br>


Enter an xpath expression to select the corresponding xml elements
<br><br>
<input type="text" name="xp" id="xp" maxlength="50" value="//row"/>
<input type="button" onclick="doXpath()" value="click to display the result"/>

</p>
</body>
</html>

Answer posted by Support on Jan 24, 2008 07:23
It seem's that I was wrong. :)
The XML Island can be used in FF - but still with limitation, all tags which have not equals work fine, but in case of configuration from XML we have
    <rows>
        <head>

The //rows/head XPath failed (most probably because head parsed by HTML tag rules)

Updated dhtmlxgrid.js , which works ( mainly ) with XML Islands in FF and Opera - attached to post
This is standard version, if you need a PRO version - just contact at support@dhtmlx.com

Attachments (2)
Answer posted by Daniel Vanesse on Jan 24, 2008 08:15
Congratulation, you have found it! Indeed, the problem came from the "head" tag which is recognized as part of the default namespace ( html in our case)
Thanks for the update, I will test that next week.
Answer posted by Larry on Feb 12, 2009 15:15
The sample of usage you provided as an attachment to this thread seems to be corrupt.  Can you resubmit, please?

Thanks,
Larry
Answer posted by Alex (support) on Feb 13, 2009 07:04

The attachment is not the sample. It contains only two js files.

Please have a look at the sample in the grid package dhtmlxGrid/samples/initialization_loading/init_grid_xml.html

http://dhtmlx.com/docs/products/dhtmlxGrid/samples/initialization_loading/init_grid_xml.html

This sample demonstrates loading data from xml stream generated using PHP, from xml string and xml island. Probably it will help.