我可以看到 itemNodes 是一个 DOM 节点列表,其中包含与标题数量相同的条目数。我想访问标题节点内的信息。我试过使用 itemNodes.childNodes[0].nodeValue
我收到错误
发生错误:TypeError: itemNodes.childNodes has no properties
将 itemNodes.item(i) 放入循环返回
标题 1:[object DOMElement] 标题 2:[object DOMElement] 标题 3:[object DOMElement] 标题 4:[object DOMElement]
我期望 DOM 节点。我做错了什么?我在 vista 机器上使用 Yahoo 小部件 4.5?我的 .KON 文件中有以下内容。
x = filesystem.readFile('sample.xml');
doc = XMLDOM.parse(x);
if(doc != null)
{
//print( doc.toXML() );
var itemNodes = doc.getElementsByTagName('title');
var firstItem = itemNodes.item(0);
print(itemNodes);
numberOfItems = itemNodes.length;
items=null;
items = new Array(numberOfItems);
for(var i = 0; i < numberOfItems; i++)
{
print("Title " + (i+1) + ": " + itemNodes );
}
}
else
{
print("An error occurred. Response status: (" + request.status + ") " + request.statusText);
}
}
catch(e)
{
print("An error occurred: " + e);
}
sample.xml如下
<!-- Edited by XMLSpy® -->
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>