XML DOM dataプロパティ
Comment オブジェクト
定義と使い方
data プロパティはコメントのテキストを設定または返します。
構文
commentNode.data
例
次のコードスニペットは、loadXMLDoc()「」を xmlDoc に読み込み、最初の <book> 要素のコメントテキストを出力します:
例
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
document.write(x[i].data);
document.write("
");
}
}
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
document.write(x[i].data);
document.write("
");
}
}
上記のコードの出力は次のとおりです:
125 Simple and Delicious Recipes (Hardcover)
試してみる »
上記の例では、ループと if 文を使用して、comment ノードのみを対象とした処理を実行しています。comment ノードのノードタイプは 8 です。
Comment オブジェクト その他の拡張