PDA

View Full Version : XML format problem?



abarickman
26 Oct 2006, 9:41 AM
Hey all,

I am trying to use the grid with Lotus Domino and have not had success and I am wondering how to debug it and if my XML is in a format that will work. Lotus Domino has a great and very useful feature where you can get the contents of a view in XML by simply using "?readviewentries" after the url. Here is an example of the XML being handed back:

- <viewentry>
- <entrydata>
<text>frmTest</text>
</entrydata>
- <entrydata>
<text>bogus 10/26/2006 12:33:50 PM</text>
</entrydata>
- <entrydata>
<text>07/05/2006 01:46:07 PM</text>
</entrydata>
- <entrydata>
<text>07/05/2006 01:46:05 PM</text>
</entrydata>
</viewentry>

I have defined my scheme as follows:
var schema = {
tagName: 'viewentry',
id: 'unid',
fields: ['form', '$8', '$4', '$5']
};

This does not raise an error but does not populate the grid. Should this work or is the problem that I am looking for the attribute from a child node?

Since I am not getting an error back can anyone tell me how I might go about debugging the empty grid?

Also want to say THANK YOU to Jack for his incredible work. The grid is fabulous esepcially for Lotus Domino web development.

jack.slocum
26 Oct 2006, 2:10 PM
Unfortunately this data format can't be read efficiently in a generic routine. I would recommend overriding the XMLDataModel's loadData method and implementing your own XML loading. It shouldn't be very difficult and since your won't be searching for nodes it will be faster anyway.

khanh3m
26 Oct 2006, 2:33 PM
Abarick,
I have tried to override the loaddata method. However, it works only on Firefox...IE seem to give me a major headache. Do you want to work on this problem together?

KN

abarickman
26 Oct 2006, 6:46 PM
Thanks Jack.

This may be a stupid question so forgive me if it is. Where can I find the code for the original loadData method? Since the js file lacks spaces (at least in the editors I have access to) I can't seem to make out the original code that I need to modify. If you could point me in the right direction I would very much appreciate it.

khanh3m, I would be happy to share anything that I can find. Please do the same. You can contact me at [email protected] to collaborate. I think we should post our findings here as well since other Domino developers will eventually be looking to do the same thing.

jack.slocum
26 Oct 2006, 7:31 PM
It's in the XMLDataModel.

Suppose your data model was called dm (like var dm = new YAHOO.ext.grid.XMLDataModel(...);):


dm.loadData = function(doc, callback, keepExisting, insertIndex){
var rowData = [];
var nodes = doc.getElementsByTagName('viewentry');
if(nodes && nodes.length > 0) {
for(var i = 0; i < nodes.length; i++) {
var node = nodes.item(i);
var colData = [];
colData.node = node;
colData.id = new String(i); // use the index
//---------------------------------------------------------------
// load your column data into the colData array from the
// entrydata elements
//---------------------------------------------------------------
rowData.push(colData);
}
}
if(keepExisting !== true){
YAHOO.ext.grid.XMLDataModel.superclass.removeAll.call(this);
}
if(typeof insertIndex != 'number'){
insertIndex = this.getRowCount();
}
YAHOO.ext.grid.XMLDataModel.superclass.insertRows.call(this, insertIndex, rowData);
if(typeof callback == 'function'){
callback(this, true);
}
this.fireLoadEvent();
};


There's everything written for you except the loading of the viewentry elements into the columns you want (I didn't know what you needed there). If you have any troubles with that let me know.

khanh3m
27 Oct 2006, 12:40 AM
Here is the code to load data from a non-categorize view.

var loadcompany = {init:function () {
var schema = {tagName:"viewentry", id:"unid",
subtagName: "entrydata",
fields:["text", "text", "text", "text"]};
var myColumns = [{header:"Dummy", width:120, sortable:true},
{header:"Company", width:200, sortable:true},
{header:"Main Contact", width:200, sortable:true},
{header:"Flag", width:200, sortable:true}];
this.dataModel = new YAHOO.ext.grid.XMLDataModel(schema);
this.dataModel.onLoad.subscribe(this.onLoad.createDelegate(this));
function money(mnt) {
return "test";
}

// the DefaultColumnModel expects this blob to define columns. It can be extended to provide
// custom or reusable ColumnModels
var colModel = new YAHOO.ext.grid.DefaultColumnModel(myColumns);
colModel.setHidden(0, true);
colModel.setHidden(3, true);
// create the Grid
this.grid = new YAHOO.ext.grid.Grid("xml-grid-example", this.dataModel, colModel);
this.grid.render();
this.dataModel.loadData = function (doc, callback, keepExisting, insertIndex) {
//debugger;
this.xml = doc;
var idField = this.schema.id;
var fields = this.schema.fields;
var rowData = [];
var nodes = doc.getElementsByTagName(this.schema.tagName);
if (nodes && nodes.length > 0) {
for (var i = 0; i < nodes.length; i++) {
var node = nodes.item(i);
var colData = [];
colData.node = node;
colData.id = this.getNamedValue(node, idField, String(i));

for (var j = 0; j <fields> 0){
var currentcolumnnode = kncolumns[j];
var mycolumnfield = currentcolumnnode.getElementsByTagName(fields[j]);
for (var k = 0; k < mycolumnfield.length; k++){
if (k == 0){
var tvalue = getElementText(mycolumnfield[k])
val = tvalue;
}
//else{
// var tvalue = getElementText(mycolumnfield[k])
// val = val + "|" + tvalue
//}
}
}
if (this.preprocessors[j]) {
val = this.preprocessors[j](val);
}
colData.push(val);
}
rowData.push(colData);
}
}
if (keepExisting !== true) {
YAHOO.ext.grid.XMLDataModel.superclass.removeAll.call(this);
}
if (typeof insertIndex != "number") {
insertIndex = this.getRowCount();
}
YAHOO.ext.grid.XMLDataModel.superclass.insertRows.call(this, insertIndex, rowData);
if (typeof callback == "function") {
callback(this, true);
}
this.fireLoadEvent();
function getElementText(node) {

if (node == null) {
return("");
}

child = node.firstChild;
foundCDATA = false;
foundPlainText = false;

while (child != null) {
if (child.nodeType == 4) { // CDATA node
result = child.nodeValue;
foundCDATA = true;
}
else {
if (child.nodeType == 3) { // Text node
result = child.nodeValue;
foundPlainText = true;
}
}
if (foundCDATA == true) {
return result
}
child = child.nextSibling
}
if (foundPlainText == false) {
return("")
}

return result;
}
};
this.dataModel.load("IEAJAXSelectACompany.xml");
}, onLoad:function () {
this.grid.getSelectionModel().selectFirstRow();
}};

The code above assumed that you have a view with 4 columns. Let me know if you need further help.

KN

galdaka
27 Oct 2006, 1:09 AM
Yo tambien estoy trabajando con el grid y Lotus Notes (Version 5.0.18).

En un principio tambien valoré la posibilidad de hacerlo con ?ReadViewEntries pero preferí no modificar el componente original.

Yo lo que hago es un ?OpenAgent y le paso como parametros la vista que quiero ver en el grid.

Dentro del agente tengo las funciones de filtrado y ordenación que se aplicarán o no en función de los argumentos que se le pasen al agente. Me parece una manera mas limpia, es cierto que se necesita un elemento de diseño mas (El propio agente), pero tambien es cierto que ese agente es generico para todas las vistas que quieras presentar.

Por otro lado, creo que si consigues realizarlo con ?Readviewentries será mas rapido; Mi solución es lenta cuando tiene que ordenadar un número elevado de documentos:

4 segundos con 1200 documentos y 12 segundos con 5000 documentos.

Espero que lo consigas con ?ReadviewEntries y compartas en código con nosotros!!!

Un saludo

khanh3m
27 Oct 2006, 8:44 AM
It would be very helpful if you can write your response in English!!!!

galdaka
28 Oct 2006, 2:55 AM
Sorry for my bad english.

I´m working with grid and Lotus Notes 5.0.18

At the begining was think to make with ?Readviwentries but i´wan´t modify the original component.

I make with ?OpenAgent and passing parameters.

In the Agent, i make the filter and sorting. It works fine.

The problem is sorting. With 1200 documents => 4 seconds. With 5000 documents => 12 seconds.

I suppose with ?ReadViweEntries is faster, I hope to get it and divide this code in forum.

abarickman
28 Oct 2006, 12:58 PM
I got it working for both Moz and IE by using this code. I left out the normal grid calls here and only provided the parts that would be specific to using this with ?readviewentries. There is one case that I know wont work and that is if your view has multi-values defined (ie. field:field2). This creates multiple text notes and for some reason the child.nextSibling does not seem to handle it. That is pretty rare so I will probably attempt to fix it the first time that I come across it. If you handle that error please post the code here.


//----------------------------
dataModel.loadData = function(doc, callback, keepExisting, insertIndex){
var rowData = [];
var nodes = doc.getElementsByTagName('viewentry');

if(nodes && nodes.length > 0) {
for(var i = 0; i < nodes.length; i++) {
var node = nodes.item(i);
var colData = [];
colData.node = node;
colData.id = node.getAttribute("unid"); // use the index

var ed=node.getElementsByTagName("entrydata")

for (x=0; x<ed.length; x++) {
try{ var val=getNodeText(ed[x]) } catch(e) { var val="" }
colData.push(val)
}
rowData.push(colData);
}
}
if(keepExisting !== true){
YAHOO.ext.grid.XMLDataModel.superclass.removeAll.call(this);
}
if(typeof insertIndex != 'number'){
insertIndex = this.getRowCount();
}
YAHOO.ext.grid.XMLDataModel.superclass.insertRows.call(this, insertIndex, rowData);
if(typeof callback == 'function'){
callback(this, true);
}
this.fireLoadEvent();
};
//--------------


//------------------------ get the value nodes from the Domino entrydata ---------------------
function getNodeText(node) {
var retValue="";
var child;
var childWValue;

if (node!=null) {
child=node.firstChild;

while (child!=null) {
if (child.nodeType=="1") {
childWValue=child.firstChild
}else{
childWValue=child
}

if (retValue=="" || retValue=="\n") {
retValue=childWValue.nodeValue;
} else {
retValue+=", " + childWValue.nodeValue
}
child=child.nextSibling;
}
return retValue
}else{
return ""
}
}
//-----------------------------------------------------------------------------------------------------------------

gizzmo
14 Nov 2006, 1:51 AM
Do you have any complete example to look at?
I'm not following how to put it all together.

In the loadData function, the only required attribute is doc, and that is the url for my view?

How should the schema look like?

Ex:



var schema = {tagname: "viewentry", id:"unid", subtagName: "entrydata",
fields:["text","text",text"]};