getName example


HTML document 

<html>

<head>
<title>example</title>
<SCRIPT>
function showType() {
 var diputree = parent.frames["diputree"].document.diputree;

 var docElem = "#/1";
 var xptr = "#xpointer(has/*[1])";
 var element = diputree.lookup(docElem,xptr);

 if ( element=="" ) {
  alert ("No elements available.");
 } else {
  var type = diputree.getName(element);
  if (type=="b") {
   alert ("The first element is a branch");
  } else {
   alert ("The first element is a leaf");
  }
 }
}
</SCRIPT>
</head>

<body>

<form>
<p>Show type of first node:
<p><input type="button" value="show" onClick="showType();">

</form>

</body>
</html>

Explanation

Look up the first node.

  var docElem = "#/1)";
  var xptr = "#xpointer(has/*[1])";
  var element = diputree.lookup(docElem,xptr);

Get the name of that node.

  var type = diputree.getName(element);

Execute on condition.

  if (type=="b") {
   alert ("The first element is a branch");
  } else {
   alert ("The first element is a leaf");
  }


diputree documentation © 2000 dipu