Skip to content Skip to sidebar Skip to footer

Parse Xml Tag Attributes Using Javascript Or Jquery?

I have one xml. Example XML is given below Premshree Pillai I need to get

Solution 1:

you need to use filter() instead of find() here because company is the root element, ie currLoanXml refers to the company element. find will look for decedent elements only

var currLoanXml = '<companysample="text"><employeeid="001"sex="M"age="20">Premshree Pillai</employee></company>';
var pic = $(currLoanXml).filter('company').attr('sample');
alert(pic);

Demo: Fiddle

Solution 2:

You go too deep

$(function() {
  var currLoanXml = '<company sample="text"><employee id="001" sex="M" age="20">Premshree Pillai</employee></company>';
  var sample = $(currLoanXml).attr('sample');
  console.log(sample);
});
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Post a Comment for "Parse Xml Tag Attributes Using Javascript Or Jquery?"