Custom Search

JavaScript XML Parser Properties

XML Parser in JavaScript comes with predefined properties that allows us to read the XML content. This article will go through all the properties getting used in the XML Parser Object.

Note:
All XML Object properties are case-sensitive.

The various properties of XML Parsers are:

  • documentElement
    documentElement property will always point to the root element of the xml document
    Syntax:
    xml_object.documentElement
  • childNodes
    childNodes property will always hold array of children nodes from the current pointing node
    Syntax:
    xml_object.current_pointing_node.childNodes[Array Index]

NOTE:
With respect to the childNodes Properties




  • getElementsByTagName
    This properties allows you to point to any tag name provided you have to specify that tag name as a parameter. So it is mandatory to know the xml structure to use this property. It always returns an array of nodes
    Syntax:
    xml_object.getElementsByTag(Tag Name)
    length
    length property is used along with childNodes/getElementsByTagName to get the number of nodes retrieved
    Syntax:
    xml_object.current_pointing_node.childNodes.length
    firstChild
    This property will point to the first occurance of the child node found from the current pointing node. (IE Specific)
    Syntax:
    xml_object.firstChild
    lastChild
    Will point to the last occurance of the child node found from the current pointing node. (IE Specific)
    Syntax:
    xml_object.lastChild
    attributes
    Allows you to access the attributes values for the elements. This property is used along with the nodeValue property
    Syntax:
    xml_object.current_pointing_node.attributes[Attribute Name/Array Index]
    nodeValue
    Return you the values assigned to the attributes. This properties is only used to extract the attribute content
    Syntax:
    xmlDoc.current_pointing_node.attributes[Attribute Name/Array Index].nodeValue
    text
    Returns the text content assigned to the tag elements. This property cannot be used for reading attribute content. Also this property can only be used for Microsoft Browsers
    Syntax:
    xml_object.current_pointing_node.text
    textContent
    Returns the text content assigned to the tag elements. This property cannot be used for reading attribute content. Also this property can only be used for Mozilla, Firefox, Opera Browsers
    Syntax:
    xml_object.current_pointing_node.textContent
    hasChildNodes
    Return boolean value indicating the current pointing node has child nodes or not
    Syntax:
    xml_object.hasChildNodes
    tagName
    Return you the element name
    Syntax:
    xml_object.current_pointing_node.tagName

Related Post

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)