javascript - Access an XML value using jQuery -
i have xml
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <soapenv:body> <sizeresponse soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"> <sizereturn xsi:type="xsd:int">1</sizereturn> </sizeresponse> </soapenv:body> </soapenv:envelope>
i want access 1 .find() not working it's giving me error in console
uncaught typeerror: object <?xml version="1.0" encoding="utf-8"?><soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"><soapenv:body><sizeresponse soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"><sizereturn xsi:type="xsd:int">0</sizereturn></sizeresponse></soapenv:body></soapenv:envelope> has no method 'getelementsbytagname'
how can access otherwise using jquery or js (if there's way using xpath plugin please provide xpath expression) ?
thank you
try this:
var xml = '<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"><soapenv:body><sizeresponse soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/"><sizereturn xsi:type="xsd:int">0</sizereturn></sizeresponse></soapenv:body></soapenv:envelope>', xmldoc = $.parsexml( xml ), $xml = $( xmldoc ); console.log($xml.find("sizereturn").html());
read docs http://api.jquery.com/jquery.parsexml/
fiddle: http://jsfiddle.net/cy5xz/
Comments
Post a Comment