views:

59

answers:

2

Hi. 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.

A: 

you can use jquery plugin like :

http://jparse.kylerush.net/

Haim Evgi
A: 

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
});
Naeem Sarfraz