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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.