ノードの名前を取得します。
getNodeName() : string
戻り値 | 説明 |
---|---|
string | ノードの名前。 |
クラス | ノード名 |
---|---|
DOMAttr | 属性の名前 |
DOMCDATASection | #cdata-section |
DOMComment | #comment |
DOMDocument | #document |
DOMDocumentFragment | #document-fragment |
DOMDocumentType | 文書タイプの名前 |
DOMElement | エレメントのタグ名 |
DOMEntity | エンティティの名前 |
DOMEntityReference | 参照先エンティティの名前 |
DOMNotation | 記法の名前 |
DOMProcessingInstruction | 命令のターゲット |
DOMText | #text |
// display newline, tabs, node
function displaynode(node, nt) {
requestScope.y = requestScope.y + nt + node.getNodeName();
if(node.getNodeValue() != null)
requestScope.y = requestScope.y + " = " + node.getNodeValue();
}
// recursive function that gets the next node
function getnext(node, nodep, nt) {
this.node = node; // node to be displayed
this.nodep = nodep; // node from previous iteration
this.nt = nt; // newline and tabs
// get first child and push down
// or if no child get next sibling
if(this.node != null) {
displaynode(this.node, this.nt);
if(this.node.getFirstChild() != null) {
getnext(this.node.getFirstChild(), this.node, this.nt + "¥t");
} else {
getnext(this.node.getNextSibling(), this.node, this.nt);
}
// or pop up one then get next sibling
} else {
if(this.nodep.getParentNode() != null) {
getnext(this.nodep.getParentNode().getNextSibling(),
this.nodep.getParentNode(),
this.nt.left(this.nt.length-1));
}
}
}
// main
if (requestScope.n != null
&& requestScope.n < database.getDocumentCount()
&& requestScope.n >= 0) {
var dc = database.getAllDocuments();
var doc = dc.getDocumentArray()[requestScope.n];
// get root
var dom = doc.getDOM();
requestScope.y = dom.getNodeName();
// get first node below root and start recursive function
var node = dom.getFirstChild();
var nt = "¥n";
getnext(node, node, nt);
} else {
requestScope.y = "Error: invalid index";
}
<schema0>
<book1>
<element0>foo</element0>
<element1>bar</element1>
</book1>
<book2>
<element0>foo</element0>
<element1>bar</element1>
</book2>
</schema0>
#document
schema0
book1
element0
#text = foo
element1
#text = bar
book2
element0
#text = foo
element1
#text = bar