XML DOM insertData() methode
Definitie en gebruik
De insertData() methode voegt een tekenreeks toe aan de annotatieknuit.
语法:
commentNode.insertData(start,string)
parameter | beschrijving |
---|---|
start | verplicht. Bepaal waar de tekens moeten worden ingevoegd. De waarde begint bij 0. |
string | verplicht. Bepaal de te voegen tekenreeks. |
beschrijving
Deze methode voegt een tekenreeks toe string in te voegen op de gespecificeerde positie start 的 Comment knooppunt tekstlocatie.
Example
The following code segment uses the JavaScript function loadXMLDoc() Load the XML file books_comment.xml Load xmlDoc, then insert a string into the first Comment node:
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Only process comment nodes
x[i].insertData(10,"Illustrated ");
document.write(x[i].data);
document.write("<br />");
}
}
The output of the above code:
(Book 6) (Illustrated Hardcover)
In this example, we use a loop and if statement to perform processing that is only for comment nodes. The node type of comment nodes is 8.
Related pages
XML DOM reference manual:CharacterData.insertData()