2013-11-25 3 views
1
   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 software.I я доступ к вебу-API «http://htp2.hitecpoint.in:98/api/blackbox/live/45», которые возвращают XML data.I хотят, чтобы разобрать узел определения местоположения, но я всегда получаю ошибку "xmlerr, не может найти элемент ". Что я делаю неправильно, пожалуйста, помогите.Как парсер XML в LiveCode

+0

Я только что ответил на этот же вопрос по программированию LiveCode для настоящих начинающих вопросов и ответов. – Mark

ответ

0

Этот сервер возвращает JSON по умолчанию. Перед тем, как сделать запрос, вам необходимо установить тип содержимого приложения/XML:

set the httpHeaders to "Content-Type: application/xml" 

Теперь сервер возвращает XML, и вы должны быть в состоянии получить необходимые узлы.

+0

Но если я нажму на эту ссылку, я получу данные ответа xml «http://htp2.hitecpoint.in:98/api/blackbox/live/45». –

+0

Да, в вашем браузере вы получаете XML, потому что ваш браузер достаточно умен, чтобы знать, что он хочет XML. В LiveCode вы получаете JSON. Просто попробуйте. Если это не сработает, тогда есть и другая проблема, но это определенно не сработает, если вы не установите httpHeaders. – Mark

+0

, где я должен поместить эти теги, чтобы установить httpHeaders в «Content-Type: application/xml», ответьте –