Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"> </script> </head> <body> <script> //check if the previous sibling node is an element node function get_previoussibling(n) { x=n.previousSibling; while (x.nodeType!=1) { x=x.previousSibling; } return x; } xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("author")[0]; document.write(x.nodeName); document.write(" = "); document.write(x.childNodes[0].nodeValue); y=get_previoussibling(x); document.write("<br>Previous sibling: "); document.write(y.nodeName); document.write(" = "); document.write(y.childNodes[0].nodeValue); </script> </body> </html>