Last time, we've got Openhab's XML Format page, which we're going to start parsing the resulting XML.
I am using Hbuilder, to use the existing app base to open a webview to load HTML pages, to achieve the effect of the app.
<script type= "Text/javascript" >$ (document). Ready (function() {$.ajax ({URL:' Http://192.168.0.19:8080/rest/items ', type:' GET ', DataType:' XML ', timeout:1000,//Set TimeoutCachefalse,//Disable CachingErrorfunction(XML) {alert ("Error loading XML Document!"); }, Success:getstudentcomplete//callback function after setting successful }); }); //gets the XML after the callback function is successful functionGetstudentcomplete (XML) {$ (XML). Find ("Item"). each (function(i) {//Find all student nodes and Traverse varName = $ ( This). Children ("name");//Get child nodes varState = $ ( This). Children ("state");//Get child nodes varLinks = $ ( This). Children ("link"); varItem_name = Name.text ();//Get node text varItem_state = State.text ();//get the properties of a node varItem_link =Links.text (); varDivclass = $ (' <li><a href= "' +item_link+ '" > ' +item_name+ ' </a></li> '); $("#main"). Find (' ul ')). Append (Divclass); }); } </script>
The HTML body section here is as follows:
<Body> <DivID= "Main"class= "Mui-content"> <ulclass= "Mui-table-view"> </ul> </Div> </Body>
We extract the name, state, and link of the XML file as a list of HTML pages. Let's take this one step today.
The results are as follows:
On the use of landscaping, we will talk about later.
——————————— original articles, reproduced please contact [email protected], this article in the Open Source Smart home Forum ———————————————
Parsing xml--with HTML JavaScript my Bishi (ii)