Javascript:
var req=xmlDoc.responseXML.selectSingleNode("//title");
alert(req.text);
正如预期的那样,返回第一个“title”节点的文本。
但是这个
var req=xmlDoc.responseXML.selectNodes("//title");
alert(req.text);
返回“未定义”。以下:
var req=xmlDoc.responseXML.selectNodes("//title").length;
alert(req);
返回“2”。我不明白。也许当我 selectNodes 它没有得到标题内的文本节点。这是我现在的猜测......这是xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog SYSTEM "catalog.dtd">
<catalog>
<decal>
<company>Victor</company>
<title>Wood Horn Blue Background</title>
<image>
<url>victor01.jpg</url>
<width>60</width>
<height>60</height>
<name>Wood Horn Blue Background</name>
<link></link>
</image>
<price>$15.00</price>
<instock>In Stock</instock>
<notes>no extra info</notes>
</decal>
<decal>
<company>Victor</company>
<title>Wood Horn without Black Ring</title>
<image>
<url>victor02.jpg</url>
<width>60</width>
<height>60</height>
<name>Wood Horn Without Black Ring</name>
<link></link>
</image>
<price>$15.00</price>
<instock>In Stock</instock>
<notes>no extra info</notes>
</decal>
</catalog>
谢谢