在这里,我试图通过 dom 解析访问美元汇率值,但由于子节点和父节点的名称相同,我仍然感到困惑。我请求你们帮助我。
<Cube>
<Cube time="20:01:33">
<Cube currency="USD" rate="1.3037"/>
<Cube currency="JPY" rate="129"/>
<Cube currency="BGN" rate="1.9558"/>
<Cube currency="CZK" rate="25.980"/>
<Cube currency="DKK" rate="7.4591"/>
<Cube currency="GBP" rate="0.85625"/>
<Cube currency="HUF" rate="294.07"/>
</Cube>
</Cube>
WinJS.xhr({ url: "", responseType: "responseXML" }).done(
function completed(request) {
var restXML = request.responseXML;
var element = restXML.documentElement;
var subElement = element.getElementsByTagName("Cube");
var dollar = subElement.item(0).attributes[0].name;
if (dollar == 'USD') {
var value = subElement.item(1).attributes[1].name;
currency1.innerText = value;
// handle completed download.
}