在jQuery中遍历XMLDOM
我是Jquery新手,正在努力学习。但是我被这个问题困住了 我收到了来自WCF服务的以下回复在jQuery中遍历XMLDOM,jquery,Jquery,我是Jquery新手,正在努力学习。但是我被这个问题困住了 我收到了来自WCF服务的以下回复 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header /> <s:Body> <GetLabelDetailsResponse xmlns="http://tempuri.org/"> <GetLabelDetailsR
<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>
有人能给我指出正确的方向,告诉我如何从回复中获得条形码状态标签的值吗
提前感谢,,
Ram您需要在(
a:
&s:
)中转义冒号
var s=$('
success: function (data) {
$(data).find("GetLabelDetailsResponse").each(function () {
alert($(this).find("GetLabelDetailsResult").text());
});
}
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 by the Ordinal positon
s.find("GetLabelDetailsResponse").each(function () {
alert($(this).find("GetLabelDetailsResult").children().children().eq(0).text());
});
//Escape the namespaces
s.find("GetLabelDetailsResponse").each(function () {
alert($(this).find("GetLabelDetailsResult > a\\:ContainerDetails > a\\:BarCodeStatus").text());
});