on mouseUp
loadPreferences
end mouseUp
command loadPreferences
local tTree
put readPreferencesToXMLTree() into tTree
if tTree is empty then
exit loadPreferences
end if
processPreferencesTree tTree
revDeleteXMLTree tTree
end loadPreferences
private function readPreferencesToXMLTree
set the itemDelimiter to slash
local tPreferencesFile
put the URL"http://htp2.hitecpoint.in:98/api/blackbox/live/45" into tPreferencesFile
local tPreferencesData, tResult
put tPreferencesFile into tPreferencesData
put the result into tResult
if tResult is not empty then
answer error "Failed to read preferences file at location: " & tPreferencesFile
return empty
end if
local tTree
put revCreateXMLTree(tPreferencesData, false, true, false) into tTree
if tTree is not an integer then
answer error "Failed to process preferences file with error: " & tTree
return empty
end if
return tTree
end readPreferencesToXMLTree
private command processPreferencesTree pTree
local tPosts
put revXMLChildNames(pTree, "ArrayOfLiveStatus/LiveStatus", return, "Location", true) into tPosts
local tListOfNames
repeat for each line tName in tPosts
put revXMLNodeContents(pTree, "ArrayOfLiveStatus/LiveStatus" & tName) & return after tListOfNames
end repeat
delete the last char of tListOfNames
local tOutput
put tListOfNames after tOutput
set the text of field "NameList" to tOutput
end processPreferencesTree
我正在使用Livecode软件。我正在访问返回xml数据的web api“http://htp2.hitecpoint.in:98/api/blackbox/live/45”。我想解析位置节点但我总是收到错误“xmlerr,找不到元素”。我做错了请帮忙。
答案 0 :(得分:0)
此服务器默认返回JSON。在发出请求之前,您需要将内容类型设置为application / xml:
set the httpHeaders to "Content-Type: application/xml"
现在服务器将返回XML,您应该能够检索所需的节点。