Get value of any attributes from XML data in Javascript
<RDService status="NOTREADY" info="Morpho_RD_Service"> <Interface id="CAPTURE" path="/127.0.0.1:11100/capture" /> <Interface id="DEVICEINFO" path="/127.0.0.1:11100/getDeviceInfo" /> </RDService>
I have the above XML response. I want the value of status from the response. I am trying to get it by the below code:
$(xmlresponse).getAttributeValue('status');
But I am getting an exception as: $(…).getAttributeValue is not a function
The jquery method to read attributes is .attr
https://api.jquery.com/attr/ which can be applied to xml:
$(xml).attr("status")
var xml = '<RDService status="NOTREADY" info="Morpho_RD_Service">' +'<Interface id="CAPTURE" path="/127.0.0.1:11100/capture" />' +'<Interface id="DEVICEINFO" path="/127.0.0.1:11100/getDeviceInfo" />' +'</RDService>' console.log($(xml).attr("status"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>