home *** CD-ROM | disk | FTP | other *** search
- function getNextNode(node)
- {
- do {
- node = node.nextSibling;
- } while (node && node.nodeType!=1);
- return node;
- }
-
- function getChildNode(node)
- {
- node = node.firstChild;
- while (node && node.nodeType != 1) {
- node = node.nextSibling;
- }
- return node;
- }
-
- function getLastChildNode(node)
- {
- node=node.lastChild;
- while (node && node.nodeType!=1) {
- node=node.previousSibling;
- }
- return node;
- }
-
- function findChildNode(node, name)
- {
- node = node.firstChild;
- while (node && node.nodeName != name) {
- node = node.nextSibling;
- }
- return node;
- }
-
- function getNodeValue(node)
- {
- return node.firstChild ? node.firstChild.nodeValue : null
- }
-
- function getParentNode(node)
- {
- return node.parentNode;
- }
-
- function getNodeByName(node, name)
- {
- for (; node && node.nodeName != name; node = getNextNode(node));
- return node;
- }
-
- function getChildNodeValue(node, name)
- {
- for (node = getChildNode(node); node && node.nodeName != name; node = getNextNode(node));
- return node ? getNodeValue(node) : null;
- }
-
- function getNodeByAttribute(node, name, attrname, attrvalue)
- {
- for (; node; node = getNextNode(node)) {
- if (node.nodeName == name && node.getAttribute(attrname) == attrvalue) return node;
- }
- return null;
- }
-
- function addAttribute(doc, node, attrname, attrvalue)
- {
- var attr = doc.createAttribute(attrname);
- attr.value= attrvalue;
- node.setAttributeNode(attr);
- return attr;
- }
-
- function addElementNode(doc, node, name)
- {
- var elementNode = doc.createElement(name);
- node.appendChild(elementNode);
- return elementNode;
- }
-
- function addTextNode(doc, node, text)
- {
- var textNode = doc.createTextNode(text);
- node.appendChild(textNode);
- return textNode;
- }
-
- function removeFirstChild(node)
- {
- var c = getChildNode(node);
- return c?node.removeChild(c):null;
- }
-
- function removeLastChild(node)
- {
- var c = getLastChildNode(node);
- return c?node.removeChild(c):null;
- }
-
- function removeChildren(node)
- {
- var c = getChildNode(node);
- while(c) {
- var n=getNextNode(c);
- node.removeChild(c);
- c=n;
- }
- }
-