2009-07-21 7 views
0

soap応答から操作名とその名前空間を見つけるための汎用テンプレートを記述する必要があります。一般的な意味は、どの操作にも適用可能です。だから私は操作名と名前空間名を知らないが、それらを取得し、私が応答を送信するときに戻って修正したい。XPATHステートメントの照会

タイプ1:ここ

は、応答の構造であり、動作のための名前空間は<soapenv:Envelope>で定義されている:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:inf="http://bad.com/abc/infrastructure" 
    xmlns:ret="http://bad.com/FirstOperationToExecute" 
    xmlns:com="http://bad.com/commercial"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <ret:retrieveSummaryRequest> 
     <!-- ... result ... --> 
    </ret:retrieveSummaryRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

タイプ2:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:inf="http://bad.com/abc/infrastructure" 
    xmlns:ret="http://bad.com/FirstOperationToExecute" 
    xmlns:com="http://bad.com/commercial"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <ret:retrieveSummaryRequest xmlns:ret="http://bad.com/FirstOperationToExecute" > 
     <!-- ... result ... --> 
    </ret:retrieveSummaryRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 
:要素 <ret:retrieveSummaryRequest>で定義された名前空間

タイプ3:デフォルトネームスペース<retrieveSummaryRequest>

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:inf="http://bad.com/abc/infrastructure" 
    xmlns:ret="http://bad.com/FirstOperationToExecute" 
    xmlns:com="http://bad.com/commercial"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <retrieveSummaryRequest xmlns="http://bad.com/FirstOperationToExecute" > 
     <!-- ... result ... --> 
    </retrieveSummaryRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

操作名と名前空間を取得するための簡単なXPath文があるかどうかを誰かに教えてもらえますか?

答えて

0

上記のすべてのXMLサンプルは、同等のインフォセットを表します。彼らはと同等です、すべてが考慮されます。違いはシリアライズされた(テキスト)フォームにのみ影響しますので、気にする必要はありません。私は右のあなたを理解していれば

は、あなたがこれらの2つの値を取得したい:

  • "http://bad.com/FirstOperationToExecute"
  • "FirstOperationToExecute"

はXSLTでこれらの値のホールドを取得するには、使用:

<xsl:template match="ret:retrieveSummaryRequest"> 
    <!-- the full URI --> 
    <xsl:value-of select="namespace-uri()" /> 

    <!-- the operation name only --> 
    <xsl:value-of select=" 
    substring-after(
     substring-after(namespace-uri(), '//'), 
     '/' 
    ) 
    " /> 
</xsl:template> 

XSLTに所属していない場合、操作naを取得する私は適切なノードを選択し、DOMに名前空間URIを要求します。擬似コード:

dom.registerNSPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); 
ret = dom.selectSingleNode("/soapenv:Envelope/soapenv:Body/*[1]"); 
nsUri = ret.namespaceURI; 
opName = nsUri.replace(".*/", ""); // whatever