0

I have a XML like

<root>
<Branch CO_CODE="9" CO_CITY_ST="AHMEDABAD"/>
<Branch CO_CODE="6" CO_CITY_ST="BANGALORE"/>
<Branch CO_CODE="4" CO_CITY_ST="DELHI"/>
<Branch CO_CODE="3" CO_CITY_ST="HYDERABAD"/>
<Branch CO_CODE="5" CO_CITY_ST="JAIPUR"/>
<Branch CO_CODE="1" CO_CITY_ST="KOLKATA"/>
<Branch CO_CODE="8" CO_CITY_ST="LUCKNOW"/>
<Branch CO_CODE="10" CO_CITY_ST="MUMBAI"/>
<Branch CO_CODE="2" CO_CITY_ST="SURAT"/>
<Branch CO_CODE="7" CO_CITY_ST="VARANASI"/>
</root>

I am try to parsing it using javascript I have done still now

$(xml).find("Branch").each(function()  
{
    var str = $(this).text() +' ';
    alert(str);
});

It is giving 10 alert but how can I show CO_CODE and CO_CITY_ST value?

1

1 Answer 1

2

CO_CODE and CO_CITY_ST are attributes of Branch tag. So you can get it using .attr

$(xml).find("Branch").each(function()  
{
    var str = $(this).text() +' ';
    var code = $(this).attr('CO_CODE'); //returns Co_CODE
    var city = $(this).attr('CO_CITY_ST'); //returns CO_CITY_ST
    alert(str);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.