2012-01-25 27 views
6
<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/><soapenv:Body><v9:ProcessShipmentReply xmlns:v9="http://fedex.com/ws/ship/v9"><v9:HighestSeverity xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">SUCCESS</v9:HighestSeverity><v9:Notifications xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v9:Severity>SUCCESS</v9:Severity><v9:Source>ship</v9:Source><v9:Code>0000</v9:Code><v9:Message>Success</v9:Message><v9:LocalizedMessage>Success</v9:LocalizedMessage></v9:Notifications><v9:Version> 
          <v9:ServiceId>ship</v9:ServiceId> 
          <v9:Major>9</v9:Major> 

          <v9:Intermediate>0</v9:Intermediate> 
          <v9:Minor>0</v9:Minor> 
         </v9:Version><v9:CompletedShipmentDetail><v9:UsDomestic xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">false</v9:UsDomestic><v9:CarrierCode xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">FDXE</v9:CarrierCode><v9:ServiceTypeDescription xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">INTL PRIORITY</v9:ServiceTypeDescription><v9:PackagingDescription xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">YOUR_PACKAGING</v9:PackagingDescription><v9:RoutingDetail xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v9:UrsaPrefixCode>9F</v9:UrsaPrefixCode><v9:UrsaSuffixCode>QNJA </v9:UrsaSuffixCode><v9:OriginLocationId>QVAA </v9:OriginLocationId><v9:OriginServiceArea>AM</v9:OriginServiceArea><v9:DestinationLocationId>QNJA </v9:DestinationLocationId><v9:DestinationServiceArea>PM</v9:DestinationServiceArea><v9:DestinationLocationStateOrProvinceCode> </v9:DestinationLocationStateOrProvinceCode><v9:AstraPlannedServiceLevel>PM</v9:AstraPlannedServiceLevel><v9:AstraDescription>INTL PRIORITY</v9:AstraDescription><v9:PostalCode>74940</v9:PostalCode><v9:StateOrProvinceCode> </v9:StateOrProvinceCode><v9:CountryCode>FR</v9:CountryCode><v9:AirportId>CDG</v9:AirportId></v9:RoutingDetail><v9:ShipmentRating xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v9:ActualRateType>PAYOR_ACCOUNT_SHIPMENT</v9:ActualRateType><v9:ShipmentRateDetails><v9:RateType>PAYOR_ACCOUNT_SHIPMENT</v9:RateType><v9:RateScale>0000000</v9:RateScale><v9:RateZone>IT001O</v9:RateZone><v9:PricingCode>ACTUAL</v9:PricingCode><v9:RatedWeightMethod>ACTUAL</v9:RatedWeightMethod><v9:CurrencyExchangeRate><v9:FromCurrency>EUR</v9:FromCurrency><v9:IntoCurrency>USD</v9:IntoCurrency><v9:Rate>1.37</v9:Rate></v9:CurrencyExchangeRate><v9:DimDivisor>0</v9:DimDivisor><v9:FuelSurchargePercent>12.5</v9:FuelSurchargePercent><v9:TotalBillingWeight><v9:Units>KG</v9:Units><v9:Value>6.0</v9:Value></v9:TotalBillingWeight><v9:TotalBaseCharge><v9:Currency>USD</v9:Currency><v9:Amount>142.27</v9:Amount></v9:TotalBaseCharge><v9:TotalFreightDiscounts><v9:Currency>USD</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalFreightDiscounts><v9:TotalNetFreight><v9:Currency>USD</v9:Currency><v9:Amount>142.27</v9:Amount></v9:TotalNetFreight><v9:TotalSurcharges><v9:Currency>USD</v9:Currency><v9:Amount>17.78</v9:Amount></v9:TotalSurcharges><v9:TotalNetFedExCharge><v9:Currency>USD</v9:Currency><v9:Amount>160.05</v9:Amount></v9:TotalNetFedExCharge><v9:TotalTaxes><v9:Currency>USD</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalTaxes><v9:TotalNetCharge><v9:Currency>USD</v9:Currency><v9:Amount>160.05</v9:Amount></v9:TotalNetCharge><v9:TotalRebates><v9:Currency>USD</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalRebates><v9:Surcharges><v9:SurchargeType>FUEL</v9:SurchargeType><v9:Description>Fuel</v9:Description><v9:Amount><v9:Currency>USD</v9:Currency><v9:Amount>17.78</v9:Amount></v9:Amount></v9:Surcharges></v9:ShipmentRateDetails><v9:ShipmentRateDetails><v9:RateType>RATED_ACCOUNT_SHIPMENT</v9:RateType><v9:RateScale>0000000</v9:RateScale><v9:RateZone>IT001O</v9:RateZone><v9:PricingCode>ACTUAL</v9:PricingCode><v9:RatedWeightMethod>ACTUAL</v9:RatedWeightMethod><v9:CurrencyExchangeRate><v9:FromCurrency>EUR</v9:FromCurrency><v9:IntoCurrency>EUR</v9:IntoCurrency><v9:Rate>1.0</v9:Rate></v9:CurrencyExchangeRate><v9:DimDivisor>0</v9:DimDivisor><v9:FuelSurchargePercent>12.5</v9:FuelSurchargePercent><v9:TotalBillingWeight><v9:Units>KG</v9:Units><v9:Value>6.0</v9:Value></v9:TotalBillingWeight><v9:TotalBaseCharge><v9:Currency>EUR</v9:Currency><v9:Amount>103.6</v9:Amount></v9:TotalBaseCharge><v9:TotalFreightDiscounts><v9:Currency>EUR</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalFreightDiscounts><v9:TotalNetFreight><v9:Currency>EUR</v9:Currency><v9:Amount>103.6</v9:Amount></v9:TotalNetFreight><v9:TotalSurcharges><v9:Currency>EUR</v9:Currency><v9:Amount>12.95</v9:Amount></v9:TotalSurcharges><v9:TotalNetFedExCharge><v9:Currency>EUR</v9:Currency><v9:Amount>116.55</v9:Amount></v9:TotalNetFedExCharge><v9:TotalTaxes><v9:Currency>EUR</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalTaxes><v9:TotalNetCharge><v9:Currency>EUR</v9:Currency><v9:Amount>116.55</v9:Amount></v9:TotalNetCharge><v9:TotalRebates><v9:Currency>EUR</v9:Currency><v9:Amount>0.0</v9:Amount></v9:TotalRebates><v9:Surcharges><v9:SurchargeType>FUEL</v9:SurchargeType><v9:Description>Fuel</v9:Description><v9:Amount><v9:Currency>EUR</v9:Currency><v9:Amount>12.95</v9:Amount></v9:Amount></v9:Surcharges></v9:ShipmentRateDetails></v9:ShipmentRating><v9:IneligibleForMoneyBackGuarantee xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">false</v9:IneligibleForMoneyBackGuarantee><v9:CompletedPackageDetails xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v9:SequenceNumber>1</v9:SequenceNumber><v9:TrackingIds><v9:TrackingIdType>EXPRESS</v9:TrackingIdType><v9:FormId>0430</v9:FormId><v9:TrackingNumber>794794712260</v9:TrackingNumber></v9:TrackingIds><v9:GroupNumber>0</v9:GroupNumber><v9:Barcodes><v9:BinaryBarcodes><v9:Type>COMMON_2D</v9:Type><v9:Value>Wyk+HjAxHTAyNzQ5NDAdMjUwHTAxHTAwMDAwMDAwMDAwMDA0MzAdRkRFHTUxMDA4NzAyMB0wMjUdHTEvMR02LjBLRx1OHUxlIFBlcmNlIE5laWdlLCA0IENoZW1pbiBkZSBWZXJib3V4HUFubmVjeSBMZSBWaWV1eB1aWh1HcmFuZG91bGllciBNYXJpZS1MYXVyZR4wNh0xMFpFSUkwNh0xMVpTb2NpZXTDoCBEZXN0aW5hdGFyaW8dMTJaMDY3MTIzNzAyMR0zMVo0MDQ5NzE5OTExMDAwMDA0MDAwMDAwMDAwMDAwNDMwMB0zMlodMTRaKipURVNUIExBQkVMIC0gRE8gTk9UIFNISVAqKh0xNVoxMDAwOTE2NDQdMjhaHUtWYWx1ZSB0byBiZSBTaG93biBpbnRvIHRoZSBpbnYdOTlaRUkwMDA0HElUHDMzLjAcRVVSHENvbnRlbnQgZGVzY3JpcHRpb24gKE11c3QgYmUgcHJvdmlkZWQgaW4gRU5HTElTHBxZHDEwLjAcHTI2WjRmZmMcHR4E</v9:Value></v9:BinaryBarcodes><v9:StringBarcodes><v9:Type>ASTRA</v9:Type><v9:Value>40497199110000047947947122604300</v9:Value></v9:StringBarcodes></v9:Barcodes><v9:AstraLabelElements><v9:Number>2</v9:Number><v9:Content>TRK#</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>3</v9:Number><v9:Content>0430</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>5</v9:Number><v9:Content>9F QNJA </v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>7</v9:Number><v9:Content>40497199110000047947947122604300</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>8</v9:Number><v9:Content>512G2/A78E/A278</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>10</v9:Number><v9:Content>7947 9471 2260</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>12</v9:Number><v9:Content>PM</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>13</v9:Number><v9:Content>INTL PRIORITY</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>15</v9:Number><v9:Content>74940</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>16</v9:Number><v9:Content> -FR</v9:Content></v9:AstraLabelElements><v9:AstraLabelElements><v9:Number>17</v9:Number><v9:Content>CDG</v9:Content></v9:AstraLabelElements><v9:Label><v9:Type>OUTBOUND_LABEL</v9:Type><v9:ShippingDocumentDisposition>RETURNED</v9:ShippingDocumentDisposition><v9:Resolution>200</v9:Resolution><v9:CopiesToPrint>1</v9:CopiesToPrint><v9:Parts><v9:DocumentPartSequenceNumber>1</v9:DocumentPartSequenceNumber><v9:Image>HUGE STUFF!!!</v9:Image></v9:Parts></v9:Label><v9:SignatureOption>SERVICE_DEFAULT</v9:SignatureOption></v9:CompletedPackageDetails></v9:CompletedShipmentDetail></v9:ProcessShipmentReply></soapenv:Body></soapenv:Envelope> 

私のWebサービスからのSOAP応答です。ColdFusion XmlSearch():名前空間を持つXPath

私はXmlSearch()<v9:image>コンテンツを取得します。

正しいXPathは何ですか? "// v9:image"でも "// image"でも動作しません!

答えて

13

あなたがXMLドキュメントのV9セクションにアクセス要素に少しあなたの構文を変更する必要がありますので、名前空間V9は、ルートではない。ここで

<cfset results = xmlSearch(myXMLDoc,"//*[local-name()='Image' and namespace-uri()='http://fedex.com/ws/ship/v9']") /> 

、あなたはXML宣言を無視しますv9を使用し、明示的にXPath検索のネームスペースをnamespace-uri()で参照し、local-name()関数を使用して要素の値を要求します。

v9がXMLドキュメントのルート(上端)で宣言されている場合、// v9:Image /を使用して試した古いXPath検索構文が機能しました。

ColdFusion XPathライブラリ実装のため、検索の実行中に名前空間コンテキストを任意に設定する方法はありません。ドキュメントのルートで宣言されているネームスペースに制限されています(XPathで検索できるデフォルトのネームスペースに注がれます)。// v9:Image /などの名前空間の別名を使用して検索を実行できます。これは、XMLをより深く理解するにつれて、新しい名前空間が導入されたときに壊れます。

SOURCE:ほとんどのXPathの実装ではSpecify xmlns namespaces in an XPath Search

+0

XMLドキュメントの検索中にエラーが発生しました。 プレフィックスは名前空間: –

+0

の引用符に解決する必要があります。 "XMLルートドキュメント宣言(v9名前空間を含む)..."とは何ですか? O.o –

+0

元の質問を完全なXML文書で更新してください。私は、v9名前空間が文書内の正しい位置に適切に宣言されていないという卑劣な疑念を持っています。何がわからないのであれば、ENTIRE xml文書を上から下に投稿してください。 –

2

この問題は、ホスト言語の任意の接頭辞と名前空間URIを登録することで対処されるが、私はthe XMLSearch docsでこれに関連する情報を参照してください(とGoogle ISNはありません多くの助け、どちらか)。以下の回避策

はその間に役立つはず:

//*[local-name()='Image'] 

これはimageいずれかからの要素(または全くない)名前空間を選択します。

あるいは、より具体的に(ショーンの答え@に示すように):これは完全に不要になることが

//*[local-name()='Image' and namespace-uri()='http://fedex.com/ws/ship/v9'] 

注、、、XPathエンジンと名前空間を登録するためのいくつかの方法が与えられました。たとえば、この完全なJavaの例を考えてみます。

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder builder = domFactory.newDocumentBuilder(); 
Document doc = builder.parse("workbook.xml"); 
XPath xpath = XPathFactory.newInstance().newXPath(); 
NamespaceContext ctx = new NamespaceContext() { 
    public String getNamespaceURI(String prefix) { 
     if ("myName".equals(prefix)) { 
      return "http://fedex.com/ws/ship/v9"; 
     } 
     return null; 
    } 
    public String getPrefix(String uri) { 
     throw new UnsupportedOperationException(); 
    } 
    public Iterator getPrefixes(String uri) { 
     throw new UnsupportedOperationException(); 
    } 
}; 
xpath.setNamespaceContext(ctx); 
XPathExpression expr = xpath.compile("//myName:Image");  

NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); 
for (int i = 0; i < nodes.getLength(); i++) { 
    System.out.println("[" + nodes.item(i).getTextContent() + "]"); 
} 

が出力:

[HUGE STUFF!!!] 

このコードは、名前空間URI http://fedex.com/ws/ship/v9で接頭辞myNameを関連付けます。

//myName:Image 

一つは、ColdFusionが同様の機能をサポートしていることを推測だろうが、私はドキュメントでそれを見つけることができませんでした:それに続く式は任意に選択されたプレフィックス名を使用して、その名前空間内のノードを参照することができます。ただし、そのような機能が存在しない場合は、ColdFusionの制限です。特に、XPath自体またはとは何も関係がありません。ソースドキュメント内のは名前空間宣言が表示されます。

関連する問題