Parsing xml--with HTML JavaScript my Bishi (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.