Java script function - XMLNode

Functions for get data/information.

  • W3C liked API are marked as blue. The behavior is the same as Java API.
  • Default return value of String is ''
  • Default return value of XMLNode is null
  • Default return value of XMLNode[] is XMLNode[0]
  • When XMLNode transfer to String, the value is getNodeValue() for attribute. For other node types, the value is getOuterHTML().
  • The java script API can be download here. You can unzip and add it to WTP JSDT's java script library for development complex script.
Function name Description Return type
getAttribute(attrName String) Get attribute String
getAttributeNS(attrName String,nameSpace String) Get attribute String
getAttributeNode(attrName String) Get attribute node XMLNode
getAttributeNodeNS(attrName String,nameSpace String) Get attribute node XMLNode
getElement(nodeName String) Get first element with given tag name String
getChildNodes() Get child nodes XMLNode[]
getElementById(id String) Get element which has attribute id=? XMLNode
getElementsByTagName(nodeName String) Find descendant that tag name is the same as gived name XMLNode[]
getElementsByTagNameNS(nodeName String,nameSpace String) Find descendant that tag name is the same as gived name XMLNode[]
getFirstChild() Get first child node XMLNode
getInnerHTML() Get text between element's start tag/end tag. String
getLastChild() Get last child node XMLNode
getLocalName() Get the local part of the qualified name String
getNextSibling() Get the node immediately following this node XMLNode
getNodeName() Get node name String
getNodeType() Return node type, ELEMENT_NODE=1, ATTRIBUTE_NODE=2, TEXT_NODE=3... int
getNodeValue() Get value of node String
getOuterHTML() Get node source text String
getOwnerDocument() Get owner document of this node XMLNode
getOwnerElement() Get owner element of attribute node XMLNode
getParentNode() Get parent node XMLNode
getPrefix() Get name space prefix String
getPreviousSibling() Get the node immediately preceding this node XMLNode
hasAttribute(attrName String) Is attribute exist is this element boolean
hasAttributeNS(attrName String,nameSpace String) Return true specify attribute name exist boolean
hasAttributes() Return true if node has any attributes boolean
hasChildNodes() Return true if child node exist boolean
xpath(xpathExpress String) Perform xpath query XMLNode[]

Above functions can be used to modify the source text of node.

Function name Description Overwrite behavior
insertAfter(text String) Insert text after this node
insertBefore(text String) Insert text before this node
remove() Remove this node setOuterHTML() and all element modification is canceled
setNodeValue(attrName String, newValue String) Set value for Attribute node or replace text content of Text node.
setOuterHTML(text String) Replace node text with gived text All element modification is canceled
Above function take no effect if node is not element
insertAfterStartTag(text String) Insert text after element's start tag
insertBeforeEndTag(text String) Insert text before elment's end tag
removeAttribute(attrName String) Remove attribute from element renameAttribute() and setAttribute()
removeElementTag() Remove the start tag/end tag of element Other element modification is canceled
renameAttribute(oldName String, newName String) Change attribute's name
renameElement(text String) Change element's tag name
setAttribute(attrName String, newValue String) Add/modify a attribute. If you rename a attribute then call this method, the nodeName must be old attribute name.
setInnerHTML(text String) For Element node, replace the text between element's start tag/end tag. For Attribute node, set it's value.
XO Free Host