473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

NodeFilter constructor in Traversal: NS_ERROR_DOM_NOT_SUPPORTED_ERR


I am trying to write functions that manipulate objects representing
dynamic tables in HTML documents in a more friendly way (to me).

I do this by creating a table object (tableObject) through a constructor
(code below) whose properties include .rows and .columns and arrays
corresponding to cells, and I can just set/get values (probably through
methods) to change the tables, with other functions adding and pruning
DOM-related nodes to the table as the case may be.

Within the constructor, I am trying to call a function described in the
DOM Traversal specification for walking the nodes of the table tree, but I
am getting an error:
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR

The function being called is a NodeFilter constructor related to the
Traversal spec. The system/browser being used is Firefox 1.5.0.4, which
apparently implements this constructor, since I have included code which
attempts to define the constructor IF it is not implemented/defined by
other systems/browsers, and FF is returning the error (not my code).
Anyone have an idea what the error is and what may be causing it?

Google has a scarcity of results and none I can find that actually
describe under what conditions the error code is/might be returned. I
can't even find anything on the Mozilla site.
============= code fragment start ===============
/*
the tableObject constructor for an existing table document object
--- argument 'documentID' is the value of the 'id' attribute of the
table element in the HTML document which is to be characterized and
manipulated
*/

function tableObject(documentID)
{
var i, node, collection;
if ((this.docObject = node = document.getElementById(documentID)) ==
null)
return (null);
if (node.nodeName.toLowerCase() != "table")
return (null);
this.type = "tableObject";
this.documentID = documentID;
this.getDocumentId = function () {
return (this.documentID);
};
this.getNode = function () {
return (this.docObject);
};
// store the THEAD, TBODY, TFOOT and their TR and TH/TH nodes for
// dynamic table

/* The line immediately below calling a NodeFilter constructor
is the one producing the error
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
*/

var nodeFilter = new NodeFilter(collectionsFilter);
var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
nodeFilter, false);
if (typeof(childNodeType) != "string")
{
var i;
if (typeof(childNodeType) != "object" ||
typeof(childNodeType.length) == "undefined")
return (null);
}
return (this);
}
function collectionsFilter(node, whatToFilter)
{
if (typeof(node) == "undefined" ||
typeof(whatToFilter) == "undefined")
return (NodeFilter.FILTER_REJECT);
if (node.getNodeType() == Node.ELEMENT_NODE)
for (i = 0; i < whatToFilter.length; i++)
if (node.getNodeName().toLowerCase() ==
whatToFilter[i].toLowerCase())
return (NodeFilter.FILTER_ACCEPT);
return (NodeFilter.FILTER_SKIP);
}

Jul 25 '06 #1
1 3402


Patient Guy wrote:

/* The line immediately below calling a NodeFilter constructor
is the one producing the error
Error: Object cannot be created in this context =
NS_ERROR_DOM_NOT_SUPPORTED_ERR
*/

var nodeFilter = new NodeFilter(collectionsFilter);
That is not supposed to work, NodeFilter as an object is only there so
that you can access the constants (e.g. NodeFilter.SHOW_ELEMENT as you
do below). You don't need any constructor function call, in the
ECMAScript binding
<http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ecma-script-binding.html>
you simply pass in a function that takes a node as an argument and
retuns a number so all you need is
var twalk = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT,
nodeFilter, false);
e.g.
document.createTreeWalker(
node,
NodeFilter.SHOW_ELEMENT,
function (node) {
// check node as needed and return one of
// FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP
},
false
)

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Tim Tyler | last post by:
Today's: "Directory Traversal Vulnerability": - http://secunia.com/advisories/10955/ More evidence tht PHP was hacked together rapidly without a great deal of thought being given to security....
2
by: ravi mannan | last post by:
Hello all, I'm trying to read an xml file and create a nested JPopupMenu from that. The first thing I want to do is to read in the xml file and put it in a Document using DOM and then do a...
1
by: guy001 | last post by:
Hi, I'm trying to traverse the DOM in a bit of a non-traditional manner and am struggling to get my head around it. Just say i have some elements like so: A |-B |-C | |-D |
2
by: xandra | last post by:
i have 2 question in breadth-first traversal.your help will be appreciated. 1. what is the purpose of the queue in breath-first traversal? 2 suppose you had a function call displayAtDepthN which...
6
by: GrispernMix | last post by:
//ques and and level order traversal file name: lab6_build_leaf_up.cpp Instructions:
7
by: desktop | last post by:
In the C++ standard page 472 it says that you can construct a std::set in linear time if the constructor gets a sorted sequence of elements. But how is this possible when insert takes logarithmic...
6
by: APEJMAN | last post by:
would you please help me? I wrote 3 separate line of code for printing my binary tree, and now I am trying to print the level-order traversal of the tree, where the nodes at each level of the tree...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. basically i need to read in a text file... shown below H H,E,L E,B,F B,A,C A,null,null c,null,D
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.