Traverse through an XML DOM in jQuery -
i new jquery , trying learn. stuck problem.
i have following response wcf service.
<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:header /> <s:body> <getlabeldetailsresponse xmlns="http://tempuri.org/"> <getlabeldetailsresult xmlns:a="http://schemas.datacontract.org/2004/07/rework" xmlns:i="http://www.w3.org/2001/xmlschema-instance"> <a:containerdetails> <a:barcodestatus>4</a:barcodestatus> <a:barcodestatusdesc /> <a:labelgs1>011030310036099721336</a:labelgs1> <a:labeltype>ea</a:labeltype> <a:numberofchildren>0</a:numberofchildren> <a:parentgs1>012030310036099421511</a:parentgs1> <a:parentserial>012030310036099421511</a:parentserial> <a:parenttype>cse</a:parenttype> <a:productcode>r0010221130</a:productcode> <a:productdescription>r0010221130-h-688 monobutyl ether</a:productdescription> <a:typename /> </a:containerdetails> </getlabeldetailsresult> </getlabeldetailsresponse> </s:body></s:envelope>
i trying parse value of barcodestatus tag. lost how can value. have following code in web page. shows values of nodes, when try find barcodestatus node, dont (balnk value).
success: function (data) { $(data).find("getlabeldetailsresponse").each(function () { alert($(this).find("getlabeldetailsresult").text()); }); }
can please point me in right direction how can value of barcodestatus tag teh response?
thanks in advance, ram
you need escape colons in xml namespaces (a:
& s:
).
example:
var s = $('<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:header /> <s:body> <getlabeldetailsresponse xmlns="http://tempuri.org/"> <getlabeldetailsresult xmlns:a="http://schemas.datacontract.org/2004/07/rework" xmlns:i="http://www.w3.org/2001/xmlschema-instance"> <a:containerdetails> <a:barcodestatus>4</a:barcodestatus> <a:barcodestatusdesc /> <a:labelgs1>011030310036099721336</a:labelgs1> <a:labeltype>ea</a:labeltype> <a:numberofchildren>0</a:numberofchildren> <a:parentgs1>012030310036099421511</a:parentgs1> <a:parentserial>012030310036099421511</a:parentserial> <a:parenttype>cse</a:parenttype> <a:productcode>r0010221130</a:productcode> <a:productdescription>r0010221130-h-688 monobutyl ether</a:productdescription><a:typename /></a:containerdetails></getlabeldetailsresult></getlabeldetailsresponse> </s:body></s:envelope>'); //find ordinal positon s.find("getlabeldetailsresponse").each(function () { alert($(this).find("getlabeldetailsresult").children().children().eq(0).text()); }); //escape namespaces s.find("getlabeldetailsresponse").each(function () { alert($(this).find("getlabeldetailsresult > a\\:containerdetails > a\\:barcodestatus").text()); }); รข
if need more comprehensive namespace support jquery check out xml namespace selectors jquery
Comments
Post a Comment