El siguiente código funciona en Chrome, pero no en IE o FireFox. ¿Alguien sabe el código de navegador cruzado apropiado?
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/SubscriptionService/Update</a:Action>
<netdx:Duplex xmlns:netdx="http://schemas.microsoft.com/2008/04/netduplex">
<netdx:Address>http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=4ed8a7ee-b124-e03e-abf0-a294e99cff73</netdx:Address>
<netdx:SessionId>177b4f47-5664-d96c-7ffa-0a8d879b67dd</netdx:SessionId>
</netdx:Duplex>
</s:Header>
<s:Body>
<Update xmlns="http://tempuri.org/">
<lstResponseStruct xmlns:b="http://schemas.datacontract.org/2004/07/FSS.Libs.Core.InterprocessData.RMS" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:DataA>
<b:ValueA>1.339565</b:ValueA>
<b:Status>None</b:Status>
</b:DataA>
<b:DataA>
<b:ValueA>120.3717</b:ValueA>
<b:Status>None</b:Status>
</b:DataA>
<b:DataA>
<b:ValueA>133.563116</b:ValueA>
<b:Status>None</b:Status>
</b:DataA>
<b:DataA>
<b:ValueA>-0.0059159999999999994</b:ValueA>
<b:Status>None</b:Status>
</b:DataA>
</lstResponseStruct>
</Update>
</s:Body>
Estos son los fragmentos de JavaScript ...
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
var nodes;
if (typeof DOMParser != "undefined")
nodes = ((new DOMParser()).parseFromString(request.responseText, "application/xml")).getElementsByTagName("*");
else {
request.responseXML.loadXML(request.responseText);
nodes = request.responseXML.getElementsByTagName("*");
}
for (var i = 0; i < nodes.length; i++) {
var element = nodes[i];
...
if ((element.localName == "Body" || element.baseName == "Body") && element.namespaceURI == "http://www.w3.org/2003/05/soap-envelope") {
body = element;
break;
}
$(body).find('DataA').each(function() {
... Do something
}
por alguna razón, en cada navegador "cuerpo" definitivamente contiene el código XML cuerpo, sin embargo, el $ (cuerpo) .find ('DataA') no devuelve resultados para IE o FireFox.
Actualización:
Añadiendo el espacio de nombres $ (cuerpo) .find ('\\ b: DataA') funciona bien para Firefox e IE, pero rompe Chrome!
Consejo: utilice el método de jQuery ['$ .parseXML'] (http://api.jquery.com/jQuery.parseXML/). Devuelve un objeto 'XMLDocument' (no un objeto jQuery). Para obtener un objeto jQuery, ajuste el valor de retorno: '$ ($. ParseXML (' Test '));' –
Mejor aún, ya que esto parece ser una solicitud de Ajax, use 'ajax' de jquery y configure' dataType 'apropiadamente (o deja que jquery lo resuelva) y ni siquiera necesitarás llamar' parseXML' directamente. –
$ (xData.responseXML) .find ("z \\: fila, fila"). Each (function() {// Do Stuff}); Parece que funciona para IE, Firefox y Chrome. – antwarpes