bind example


HTML document 

<html>

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

 var docElement = "#/1";
 var newElement = "#xpointer(has/b/lt)";
 var atBegin = "#xpointer(*/*/*)";


 var newElementText = 
        diputree.bind (docElement, newElement, atBegin);
 diputree.setValue(newElementText,++counter);

 diputree.refresh (100);
}

function display() {
 var diputree = parent.frames["diputree"].document.diputree;
 var xml = diputree.save("#xpointer(/)");
 alert (xml);
}
</SCRIPT>
</head>

<body>

<form>
<p>Add a branch:
<p><input type="button" value="insert" onClick="bind();">

<p>Display XML:
<p><input type="button" value="display" onClick="display();">
</form>

</body>
</html>

Explanation

First the variables are declared and initialized.

We will use the document element as our context

 var docElement = "#/1";

We create an xpointer with the following steps 

  1. has
  2. b
  3. lt

 var newElement = "#xpointer(has/b/lt)";

The elements should be bound at the end 

 var atEnd = "#xpointer(*/*/*)";

Call the bind() method to perform the stepwise creation and binding of <has>, <b> and <lt>.

 var newElementText = 
        diputree.bind (docElement, newElement, atEnd);


diputree documentation © 2000 dipu