ノード情報のプロパティ

nodeNameプロパティ

ノードの名前(XML文書に記述した<top>、<単価 yen=>などの要素名や属性名)。参照のみ、値の設定はできない。以下のノードには名前を付けらない。そこで以下のように#付きの標準名を使う。
  Documentノード ・・・ #document
  Textノード ・・・ #text
  Commentノード ・・・ #comment
  CDATASectionノード・・・ #cdata-sectio

nodeTypeプロパティ・・・ノードの型(オブジェクト型)を示す数値コード

nodeTypeStringプロパティ・・・ノードの型を文字列で示す

nodeValueプロパティ・・・ノードがもつ値

■各プロパティ対応表

nodeTypeString nodeType nodeName nodeValue
Element 1 要素名 null
Attribute 2 属性名 属性値
Text 3 #text テキスト内容
CDATASection 4 #cdata-section CDATAの内容
EntityReference(実体参照) 5 参照されるEntity名 null
Entity(実体) 6 Entity名 null
ProcessingInstruction(処理命令) 7 処理命令のターゲット ターゲットを除いた内容
Comment 8 コメント内容 コメント内容
Document 9 #document null
DocumentType(文書の型) 10 文書型名 null
DocumentFragment(文書の断片) 11 #document-fragment null
Notation(表記) 12 表記法名 null

 

[サンプルXML文書を表示](下のフレームに)

XMLソース

<?xml version="1.0" encoding="Shift_JIS" ?>
<家系>私の一族
<親>お父さんお母さん</親>
<姉>お姉さん
  <おい>お姉さんの息子</おい>
 </姉>
<私>おいら
  <長男>長男
<孫1>長男の娘</孫1>
</長男>
 </私>
<叔母>叔母さん
<従兄弟>叔母さんの息子</従兄弟>
</叔母>
</家系>

XSLソース

<SCRIPT language="JavaScript"><!--
function test(){
var xmlobj=new ActiveXObject("MSXML2.DOMDocument");
xmlobj.async=false;
xmlobj.load("node01.xml");
var str = "";
str="nodeNameは:"+xmlobj.documentElement.childNodes.item(0).nodeName+ "\n\t";
str += "nodeTypeは:"+xmlobj.documentElement.childNodes.item(0).nodeType+ "\n\t";
str += "nodeTypeStringは:"+xmlobj.documentElement.childNodes.item(0).nodeTypeString+ "\n\t";
str += "nodeValueは:"+xmlobj.documentElement.childNodes.item(0).nodeValue+ "\n\n";
str += "nodeNameは:"+xmlobj.documentElement.childNodes.item(3).nodeName+ "\n\t";
str += "nodeTypeは:"+xmlobj.documentElement.childNodes.item(3).nodeType+ "\n\t";
str += "nodeTypeStringは:"+xmlobj.documentElement.childNodes.item(3).nodeTypeString+ "\n\t";
str += "nodeValueは:"+xmlobj.documentElement.childNodes.item(3).nodeValue;
result.innerText = str;
}
//--></SCRIPT></HEAD>
<BODY>
<button onclick="test()">サンプルを実行</button>
<P id="result" style="margin-left:30px;border:1px solid green"> </P>

end(04/4/28)