XMLDocument

This object is available to unprivileged JavaScript. It implements the following interfaces:

Constants

short DOCUMENT_POSITION_DISCONNECTED = 1
short DOCUMENT_POSITION_PRECEDING = 2
short DOCUMENT_POSITION_FOLLOWING = 4
short DOCUMENT_POSITION_CONTAINS = 8
short DOCUMENT_POSITION_CONTAINED_BY = 16
short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32
The nsIDOMNode interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree.

For more information on this interface please see http://www.w3.org/TR/DOM-Level-2-Core/

short ELEMENT_NODE = 1
short ATTRIBUTE_NODE = 2
short TEXT_NODE = 3
short CDATA_SECTION_NODE = 4
short ENTITY_REFERENCE_NODE = 5
short ENTITY_NODE = 6
short PROCESSING_INSTRUCTION_NODE = 7
short COMMENT_NODE = 8
short DOCUMENT_NODE = 9
short DOCUMENT_TYPE_NODE = 10
short DOCUMENT_FRAGMENT_NODE = 11
short NOTATION_NODE = 12

Properties

boolean async

Whether to load synchronously or asynchronously. The default is async==true.

readonly NamedNodeMap attributes

readonly String baseURI

readonly String characterSet

readonly NodeList childNodes

readonly String contentType

readonly AbstractView defaultView

The nsIDOMDocumentView interface is a datatype for a document that supports views in the Document Object Model.

For more information on this interface please see http://www.w3.org/TR/DOM-Level-2-Views

String dir

readonly DocumentType doctype

The nsIDOMDocument interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data. Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the nsIDOMDocument interface also contains the factory methods needed to create these objects.

For more information on this interface please see http://www.w3.org/TR/DOM-Level-2-Core/

readonly Element documentElement

String documentURI

readonly nsIDOMDOMConfiguration domConfig

readonly Node firstChild

readonly DOMImplementation implementation

readonly String inputEncoding

readonly Node lastChild

readonly String lastModified

readonly String localName

readonly Location location

readonly String namespaceURI

readonly Node nextSibling

readonly String nodeName

readonly short nodeType

String nodeValue

readonly Document ownerDocument

readonly Node parentNode

readonly String preferredStylesheetSet

This attribute indicates the preferredStylesheetSet as set by the author. It is determined from the order of stylesheet declarations and the Default-Style HTTP headers. See [[HTML4]]. If there is no preferred stylesheet set, this attribute returns the empty string. The case of this attribute must exactly match the case given by the author where the preferred stylesheet is specified or implied.

String prefix

readonly Node previousSibling

readonly String referrer

boolean strictErrorChecking

readonly StyleSheetList styleSheets

String textContent

String title

readonly String xmlEncoding

boolean xmlStandalone

String xmlVersion


Methods

void addBinding ( Element elt , String bindingURL ) void addEventListener ( String type , EventListener listener , boolean useCapture ) Node adoptNode ( Node source ) Node appendChild ( Node newChild ) Node cloneNode ( boolean deep ) short compareDocumentPosition ( Node other ) Attr createAttribute ( String name ) Attr createAttributeNS ( String namespaceURI , String qualifiedName ) CDATASection createCDATASection ( String data ) Comment createComment ( String data ) DocumentFragment createDocumentFragment ( ) Element createElement ( String tagName ) Element createElementNS ( String namespaceURI , String qualifiedName ) EntityReference createEntityReference ( String name ) Event createEvent ( String eventType ) XPathExpression createExpression ( String expression , XPathNSResolver resolver ) NodeIterator createNodeIterator ( Node root , int whatToShow , NodeFilter filter , boolean entityReferenceExpansion ) XPathNSResolver createNSResolver ( Node nodeResolver ) ProcessingInstruction createProcessingInstruction ( String target , String data ) Range createRange ( ) Text createTextNode ( String data ) TreeWalker createTreeWalker ( Node root , int whatToShow , NodeFilter filter , boolean entityReferenceExpansion ) boolean dispatchEvent ( Event evt ) nsISupports evaluate ( String expression , Node contextNode , XPathNSResolver resolver , short type , nsISupports result ) Range evaluateFIXptr ( String expression ) nsIXPointerResult evaluateXPointer ( String expression ) Element getAnonymousElementByAttribute ( Element elt , String attrName , String attrValue ) NodeList getAnonymousNodes ( Element elt ) Element getBindingParent ( Node node ) BoxObject getBoxObjectFor ( Element elt ) Element getElementById ( String elementId ) NodeList getElementsByTagName ( String tagname ) NodeList getElementsByTagNameNS ( String namespaceURI , String localName ) nsISupports getFeature ( String feature , String version ) nsIVariant getUserData ( String key ) boolean hasAttributes ( ) boolean hasChildNodes ( ) Node importNode ( Node importedNode , boolean deep ) Node insertBefore ( Node newChild , Node refChild ) boolean isDefaultNamespace ( String namespaceURI ) boolean isEqualNode ( Node arg ) boolean isSameNode ( Node other ) boolean isSupported ( String feature , String version ) boolean load ( String url ) Document loadBindingDocument ( String documentURL ) String lookupNamespaceURI ( String prefix ) String lookupPrefix ( String namespaceURI ) void normalize ( ) void normalizeDocument ( ) void removeBinding ( Element elt , String bindingURL ) Node removeChild ( Node oldChild ) void removeEventListener ( String type , EventListener listener , boolean useCapture ) Node renameNode ( Node node , String namespaceURI , String qualifiedName ) Node replaceChild ( Node newChild , Node oldChild ) void setBoxObjectFor ( Element elt , BoxObject boxObject ) nsIVariant setUserData ( String key , nsIVariant data , nsIDOMUserDataHandler handler )

void addBinding ( Element elt , String bindingURL )

Arguments:
elt
bindingURL

void addEventListener ( String type , EventListener listener , boolean useCapture )

This method allows the registration of event listeners on the event target. If an EventListener is added to an EventTarget while it is processing an event, it will not be triggered by the current actions but may be triggered during a later stage of event flow, such as the bubbling phase.

If multiple identical EventListeners are registered on the same EventTarget with the same parameters the duplicate instances are discarded. They do not cause the EventListener to be called twice and since they are discarded they do not need to be removed with the removeEventListener method.

Arguments:
type: The event type for which the user is registering
listener: The listener parameter takes an interface implemented by the user which contains the methods to be called when the event occurs.
useCapture: If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered EventListener before being dispatched to any EventTargets beneath them in the tree. Events which are bubbling upward through the tree will not trigger an EventListener designated to use capture.

Node adoptNode ( Node source )

Arguments:
source

Node appendChild ( Node newChild )

Arguments:
newChild

Node cloneNode ( boolean deep )

Arguments:
deep

short compareDocumentPosition ( Node other )

Arguments:
other

Attr createAttribute ( String name )

Arguments:
name

Attr createAttributeNS ( String namespaceURI , String qualifiedName )

Arguments:
namespaceURI
qualifiedName

CDATASection createCDATASection ( String data )

Arguments:
data

Comment createComment ( String data )

Arguments:
data

DocumentFragment createDocumentFragment ( )


Element createElement ( String tagName )

Arguments:
tagName

Element createElementNS ( String namespaceURI , String qualifiedName )

Arguments:
namespaceURI
qualifiedName

EntityReference createEntityReference ( String name )

Arguments:
name

Event createEvent ( String eventType )

Arguments:
eventType

XPathExpression createExpression ( String expression , XPathNSResolver resolver )

Arguments:
expression
resolver

NodeIterator createNodeIterator ( Node root , int whatToShow , NodeFilter filter , boolean entityReferenceExpansion )

Arguments:
root
whatToShow
filter
entityReferenceExpansion

XPathNSResolver createNSResolver ( Node nodeResolver )

Arguments:
nodeResolver

ProcessingInstruction createProcessingInstruction ( String target , String data )

Arguments:
target
data

Range createRange ( )


Text createTextNode ( String data )

Arguments:
data

TreeWalker createTreeWalker ( Node root , int whatToShow , NodeFilter filter , boolean entityReferenceExpansion )

Arguments:
root
whatToShow
filter
entityReferenceExpansion

boolean dispatchEvent ( Event evt )

This method allows the dispatch of events into the implementations event model. Events dispatched in this manner will have the same capturing and bubbling behavior as events dispatched directly by the implementation. The target of the event is the EventTarget on which dispatchEvent is called.

Arguments:
evt: Specifies the event type, behavior, and contextual information to be used in processing the event.
Returns:
Indicates whether any of the listeners which handled the event called preventDefault. If preventDefault was called the value is false, else the value is true.

nsISupports evaluate ( String expression , Node contextNode , XPathNSResolver resolver , short type , nsISupports result )

Arguments:
expression
contextNode
resolver
type
result

Range evaluateFIXptr ( String expression )

Evaluate FIXptr expression. FIXptr is a W3C NOTE, see

http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm

Arguments:
expression: FIXptr string.
Returns:
The range object that results from evaluation

nsIXPointerResult evaluateXPointer ( String expression )

Evaluate XPointer expression.

Arguments:
expression

Element getAnonymousElementByAttribute ( Element elt , String attrName , String attrValue )

Arguments:
elt
attrName
attrValue

NodeList getAnonymousNodes ( Element elt )

Arguments:
elt

Element getBindingParent ( Node node )

Arguments:
node

BoxObject getBoxObjectFor ( Element elt )

Arguments:
elt

Element getElementById ( String elementId )

Arguments:
elementId

NodeList getElementsByTagName ( String tagname )

Arguments:
tagname

NodeList getElementsByTagNameNS ( String namespaceURI , String localName )

Arguments:
namespaceURI
localName

nsISupports getFeature ( String feature , String version )

Arguments:
feature
version

nsIVariant getUserData ( String key )

Arguments:
key

boolean hasAttributes ( )


boolean hasChildNodes ( )


Node importNode ( Node importedNode , boolean deep )

Arguments:
importedNode
deep

Node insertBefore ( Node newChild , Node refChild )

Arguments:
newChild
refChild

boolean isDefaultNamespace ( String namespaceURI )

Arguments:
namespaceURI

boolean isEqualNode ( Node arg )

Arguments:
arg

boolean isSameNode ( Node other )

Arguments:
other

boolean isSupported ( String feature , String version )

Arguments:
feature
version

boolean load ( String url )

Load an XML document.

Arguments:
url: URL to an XML document.
Returns:
True if load successfull.

Document loadBindingDocument ( String documentURL )

Arguments:
documentURL

String lookupNamespaceURI ( String prefix )

Arguments:
prefix

String lookupPrefix ( String namespaceURI )

Arguments:
namespaceURI

void normalize ( )


void normalizeDocument ( )


void removeBinding ( Element elt , String bindingURL )

Arguments:
elt
bindingURL

Node removeChild ( Node oldChild )

Arguments:
oldChild

void removeEventListener ( String type , EventListener listener , boolean useCapture )

This method allows the removal of event listeners from the event target. If an EventListener is removed from an EventTarget while it is processing an event, it will not be triggered by the current actions. EventListeners can never be invoked after being removed. Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect.

Arguments:
type: Specifies the event type of the EventListener being removed.
listener: The EventListener parameter indicates the EventListener to be removed.
useCapture: Specifies whether the EventListener being removed was registered as a capturing listener or not. If a listener was registered twice, one with capture and one without, each must be removed separately. Removal of a capturing listener does not affect a non-capturing version of the same listener, and vice versa.

Node renameNode ( Node node , String namespaceURI , String qualifiedName )

Arguments:
node
namespaceURI
qualifiedName

Node replaceChild ( Node newChild , Node oldChild )

Arguments:
newChild
oldChild

void setBoxObjectFor ( Element elt , BoxObject boxObject )

Arguments:
elt
boxObject

nsIVariant setUserData ( String key , nsIVariant data , nsIDOMUserDataHandler handler )

Arguments:
key
data
handler

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
August 5, 2005, 2:54 am liboni dot stefano at libero dot it
In case you are trying to access a DOM and you'll find out that the getElementById method doesn't work on nodes that are added dinamically (see https://bugzilla.mozilla.org/show_bug.cgi?id=252774), you can use something like that (you need to know the tag name):

function myGetElementById(xmlDoc,id) {
var elems = xmlDoc.getElementsByTagName("tag");

for(var i = 0, len = elems.length; i < len; i++)
if(elems.item(i).getAttribute("idAttribute") == id)
return elems.item(i);

return null;
}

you'll lose performance, but it works until the bug is fixed.
January 5, 2005, 7:05 am johannes at kutsam dot at
getElementById can only get Tags that are of the namespace HTML or XUL.
I passed some data as XML to my XUL app. Only if set
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" on the root element the function getElementById would work - otherwise it would always return.

In plain XML, you need to make sure that some attribute is declared as an id in a DTD - Neil

Copyright © 1999 - 2005 XULPlanet.com