开发者

Help with parsing / tranversing XML in JavaScript?

I need a little direction on how to parse this in JavaScript.

I want to list the total number of buildings and in each building, the total number of tenants.

My XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<AppManager-response uri="/AppManager/xml/ListBuildings">
    <result>
        <response method="ListBuildings">
            <Building Name="Broadway Business Center" TYPE="Commercial">
                <Tenant DISPLAYNAME="ABC Company" TYPE="Owner"/>
                <Tenant DISPLAYNAME="123 Company" TYPE="Renter"/>
            </Building>
            <Building Name="Seniors Residence" TYPE="Private">
                <Tenant DISPLAYNAME="Ricky Ricardo" TYPE="Owner"/>
                <Tenant DISPLAYNAME=开发者_运维技巧"Bob Barker" TYPE="Owner"/>
                <Tenant DISPLAYNAME="Tony Randal" TYPE="Renter"/>
            </Building>
        </response>
    </result>
</AppManager-response>

I've been playing around with the examples at w3schools XML DOM traverse Node tree - but it's not working for me.

Sorry, I'm just a newbie in this.


you can use jquery plugin like :

http://jparse.kylerush.net/


You could use the jQuery library to help you out, take a look at this code sample.

var myXml = "<your xml>";
$(myXml).find("Building").each(function() {
    var iTotalTenants = $(this).find("Tenant").length;

    // now show your results
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜