Tôi có cảm biến nhiệt độ truyền nhiệt độ của ba tổ ong và muốn phân tích luồng XML để cung cấp giá trị cuối cùng của cảm biến.Phân tích XML bằng Javascript (trong Google Scripts)
Tôi muốn có:
- Sensor 1: 75 độ (Cập nhật: 09:04)
- Sensor 2: 75 độ (Cập nhật: 09:04)
, vv
tôi đang chạy sau kịch bản trong Google Scripts, nhưng giữ nhận được một lỗi:
Cannot find function getContentText in object <?xml version="1.0" encoding="UTF-8"?>
Đây là kịch bản đơn giản:
function XMLing() {
var response = UrlFetchApp.fetch("https://api.cosm.com/v2/feeds/79697.xml?key=[private key here]");
var doc = Xml.parse(response.getContentText(), true);
var records = doc.getElements("current_value");
var details = records[0].getText();
return details;
}
Đây là XML:
<eeml xmlns="http://www.eeml.org/xsd/0.5.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.5.1" xsi:schemaLocation="http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd">
<environment updated="2012-10-21T00:44:32.162393Z" created="2012-10-10T21:19:43.373591Z" id="79697" creator="https://cosm.com/users/greennomad">
<private>false</private>
<data id="sensor1tem">
<current_value at="2012-10-21T00:44:32.019058Z">67.00</current_value>
<max_value>618.0</max_value>
<min_value>611.0</min_value>
</data>
<data id="sensor2tem">
<current_value at="2012-10-21T00:44:32.019058Z">60.57</current_value>
<max_value>61.5</max_value>
<min_value>60.41</min_value>
</data>
...
Có lẽ, bạn đang sử dụng phương pháp lỗi thời của API. Tôi khuyên bạn nên kiểm tra tài liệu API – Jay