javascript - Accessing / Parsing SOAP Messages (using JQuery) -
in example given in jquery.parsexml() documentation, if simple xml given
var xml = "<rss version='2.0'><channel><title>rss title</title></channel></rss>"
is replaced soap snippet, 1 below
var xml = "<xyz:servicename>getdetails</xyz:servicename>"
i invalid xml error or invalid/unexpected token error.
what should procedure access value inside <xyz:servicename>
tag?
jquery.parsexml()
creates xml document. invalid xml here because using namespace xyz
not defined.
so can define root element namespace definition (any url do) , works fine - see demo below:
var xml = `<root xmlns:xyz="http://www.w3.org/tr/html4/"> <xyz:servicename>getdetails</xyz:servicename> </root>`; console.log(jquery(jquery.parsexml(xml)) .find('root').html());
.as-console-wrapper{top:0;max-height:100%!important}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
but snippets, can $(xml)
:
var xml = `<xyz:servicename>getdetails</xyz:servicename>`; console.log($(xml).prop('outerhtml'));
.as-console-wrapper{top:0;max-height:100%!important}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment