XPath->DOM

3 views
Skip to first unread message

Cezary

unread,
Apr 27, 2009, 12:55:37 PM4/27/09
to DOMAssistant
Hello.

I have a small code, that using XPath, but I want to make code work
without XPath. The code is:

function makeQlist(paths, contextNode)
{
var ul = null;
var result = document.evaluate(paths.join(' | '), contextNode, null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

var node;

while ((node = result.iterateNext()) != null){
if (ul === null)
{
ul = document.createElement('ul');
}
var li = document.createElement('li');
switch (node.tagName.toLowerCase())
{
case 'fieldset':
li.textContent = node.getElementsByTagName('legend')
[0].textContent;
break;
case 'table':
li.textContent = node.caption.textContent;
break;
default:
li.textContent = node.textContent;
}

ul.appendChild(li);
var nestedList = makeQlist(paths, node);
if (nestedList !== null)
{
li.appendChild(nestedList);
}
}
return ul;
}

window.onload = function()
{
document.body.appendChild(makeQlist(['h2', 'form/fieldset[legend]',
'fieldset[legend]', 'table[caption]'], document.body));
};

I need help with the transition from the XPath to DOM. Can someone
point me to rewrite the code using Domassistant? (cssByDOM?)

--
CT
Reply all
Reply to author
Forward
0 new messages