XML DOM » Node » previousSibling

Syntax:
node.previousSibling

This property returns the previous node in the parent's child list, or null if there is none or the node is of a type that cannot be an child node (Attr, Document, DocumentFragment).

Examples

Code:
XML:

<passeriformes>
   <family>
      <f_name>Alaudidae</f_name>
      <species>Woodlark</species>
      <species>Skylark</species>
      <species>Shore Lark</species>
   </family>
   <family>
      <f_name>Motacillidae</f_name>
      <species>Rock Pipit</species>
      <species>Water Pipit</species>
      <species>Yellow Wagtail</species>
   </family>
   <family>
      <f_name>Turdidae</f_name>
      <species>Robin</species>
      <species>Nightingale</species>
      <species>Blackbird</species>
   </family>
</passeriformes>

VBScript:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("passeriformes.xml")

Dim lastChild, prevChild
Set lastChild = objXMLDoc.documentElement.lastChild
Set prevChild = lastChild.previousSibling
document.write(prevChild.text)
Output:
Motacillidae Rock Pipit Water Pipit Yellow Wagtail
Explanation:

This example uses the 'passeriformes.xml' file which details the bird families belonging to that order. It first gets the lastChild node of the root, and then uses the previousSibling property to print the text of the node that precedes it.

Language(s): VBScript XML