xml, jquery, html5

I have jquery, xml call, and try to return some value while reading it. Please read the comment below and you will know my questions.

function fnGetBondAmount() {
    $.ajax({
        url: "http://localhost:5489/BondList.xml",
        success: function (xml) {
            parseSelectXMLBondAmountList(xml, "bondAmount", "CA", "DMV Traffic Violators School Classroom")
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("Status: " + xhr.status);
            alert("Error: " + thrownError);
        }
    });
} 
function parseSelectXMLBondAmountList(xml, selectid, bondState, bondName) {
    var html = "";
    $('#' + selectid).prop("disabled", false);
    $(xml).find('GeneralInformation').each(function (i,e) {
        {
            if(bondState==$(this).find('State').text())
            {
                var selectedBondName = $(this).find('Name').text();
                if (selectedBondName == bondName) {
                    var selectedBondName = $(this).find('Name').text();
		    // code begin
			return me Coverage Type value (in this case it will be List)
			return me Amount 'Min' and 'Max' value (in this case it will be 10000, 10000)
		   // code end
                 }
             }            
        }
    });
    alert(html);
}


<Surety>
  <SuretyLine>
    <Commercial>
	<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">DMV Traffic Violators School Classroom</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>          
         </GeneralInformation>
        <Coverage Type="List">
          <Amount  PrefillValue="No" Min="10000" Max="10000" Year="1">10000</Amount>
         </Coverage>              
      </Bond>
      <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">DMV Traffsdfasdfads</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>          
         </GeneralInformation>
        <Coverage Type="List">
          <Amount  PrefillValue="No" Min="10000322" Max="100032430" Year="1">10000</Amount>
         </Coverage>              
      </Bond>
</Commercial>
  </SuretyLine>
</Surety>

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You can try this
  function parseSelectXMLBondAmountList(xml, selectid, bondState, bondName) {
    var html = "";
    
    $(xml).find('Bond').each(function (i,bond) {
      if (bondState == $(bond).find('State').text() 
          && bondName == $(bond).find('Name').text()) {

        var coverage = $(bond).find('Coverage');
        var type = coverage.attr('Type');
        var amount = coverage.find('Amount');
        var min = amount.attr('Min');
        var max = amount.attr('Min');
        html = "Type=" + type + ", Min = " + min + ", Max = " + max;
      }
    });
    alert(html);
  } 

Open in new window

Note: The code takes a short cut by using find() on the bond node to find elements in grandchildren. This will work as long as the element's are unique in other words searching for 'State' relative to the bond node will work as long as there are not more than one child nodes with a State node - in which case you would need to find the appropriate grandchild to distinguish between the different versions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
with your codes and xml. the alert now show blank.
0
ITsolutionWizardAuthor Commented:
I got it working now. Thanks.
0
Julian HansenCommented:
you are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.