Parsing an XML array using jQuery

I ran into the problem of passing XML using jQuery. I get an empty array when switching to jquery. Please help me how to get data from an XML array. I mentioned the code below.

XML

<?xml version="1.0" encoding="UTF-8"?>
<json>
   <json>
     <CustomerName>999GIZA MID INSURANCEAND SERVICES PVT LTD</CustomerName>
      <mobiLastReceiptDate>null</mobiLastReceiptDate>
   </json>
   <json>

      <CustomerName>A  SHRIVENGATESH</CustomerName>
      <mobiLastReceiptDate>null</mobiLastReceiptDate>
   </json>
   <json>
      <CustomerName>A 1 PROCESS</CustomerName>
      <mobiLastReceiptDate>null</mobiLastReceiptDate>
   </json>
   <json>
      <CustomerName>A A A ENTERPRISES</CustomerName>
      <mobiLastReceiptDate>null</mobiLastReceiptDate>
   </json>
   <json>

      <CustomerName>A ALAGUSUNDARAM</CustomerName>
      <mobiLastReceiptDate>null</mobiLastReceiptDate>
   </json>
</json>

Jquery

page_response=getResponse("yyyURL");

page_response.success(function(data){
console.log(data.results[0]);
console.log($( data ).find( "CustomerName" ));

$(data).find("json").each(function(i, item) {
var heures = $(item).attr("CustomerName");
var nbr = $(item).attr("EMI");

<!--- Am getting array.. ineed to get name and EMI-->
console.log(heures);
});

});
+4
source share
2 answers

EMIand CustomerNameare elements under json, so you can use . find () to find these elements, and then text () to get its value.

$(data).find("json").each(function (i, item) {
    var heures = $(item).find("CustomerName").text();
    var nbr = $(item).find("EMI").text();
    console.log(heures);
});

. attr () is used to get the value of an element attribute, such as<json EMI="abc">...</json>

+4
source

node, xml-: "node ". , node XML-, jquery.find(), - node, jquery.attr().

, jquery.val() jQuery.text() - , .

, !

!!

0

All Articles