1

私はJqueryが初めてで、学ぼうとしています。しかし、私はこの問題に悩まされています。

WCF サービスから次の応答があります。

<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>

BarCodeStatus タグの値を解析しようとしています。しかし、どうすればこの値を取得できるかわかりません。Web ページに次のコードがあります。これはすべてのノードの値を示していますが、BarCodeStatus ノードを見つけようとすると、何も取得できません (balnk 値)。

success: function (data) {
    $(data).find("GetLabelDetailsResponse").each(function () {
        alert($(this).find("GetLabelDetailsResult").text());
    });
}

応答からBarCodeStatusタグの値を取得する方法について、誰かが私を正しい方向に向けることができますか?

前もってありがとう、ラム

4

1 に答える 1

0

XML 名前空間( a:& )のコロンをエスケープする必要がありますs:

例:

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());
});
​

jquery のより包括的な名前空間サポートが必要な場合は、jQuery の XML 名前空間セレクターを確認してください。

于 2012-07-06T22:05:35.410 に答える