Monday, March 28, 2011

Descending a Dom tree and making table records.

function descend(xml) {
 function descendnew(xml,body) {
 
var r=[];

if(recNode(xml,r)) {
  element = newRow('TD',r);
  body.appendChild(element);
  if(xml.attributes) {
    var len = xml.attributes.length;
    for(var i=0; i < len;i++)
       descendnew(xml.attributes[i],body);
    }

  if(xml.childNodes) {
    count++;
    var len = xml.childNodes.length;
    for(var i=0; i < len;i++) {
      descendnew(xml.childNodes[i],body);
 
 }
    count--;
    }
}
else {
  alert('rejected node');
   return 0;
 }
return 1;
}

In the the end, the routine ends up with a second Dom tree, an html row version of the standard Dom node, with appropriate header names. It was sort of fascinating,and still is, to reverse engineer all the rules of Dom attributes.

So I go from Dom tree to and from record format using a standard record definition for a node:   'Type','Self','Span','Parent','Name','Value', my best guess of a Dom node. The Self and Span pointers are reletavie nesting containers as in this article, by Hillyer.

At the end of the chain, the web publishers has access to simple sql syntax inside his document, for general queries on XML databases.

No comments: