2012-01-25 17 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> 

Đây là phản hồi SOAP của tôi, từ dịch vụ web của tôi.ColdFusion XmlSearch(): XPath với các không gian tên

Tôi muốn XmlSearch() để nhận nội dung <v9:image>.

XPath phù hợp là gì? "// v9: image" hoặc "// image" không hoạt động!

Trả lời

13

Các v9 namespace không là cội rễ, vì vậy bạn sẽ phải thay đổi cú pháp bạn một chút để các yếu tố truy cập trong phần v9 của doc XML:

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

Ở đây, bạn bỏ qua khai báo XML của v9 và tham chiếu rõ ràng vùng tên trong tìm kiếm XPath qua namespace-uri() và yêu cầu giá trị của phần tử với hàm local-name().

Nếu v9 được khai báo ở gốc (ở trên cùng) của tài liệu XML, cú pháp tìm kiếm XPath cũ bạn đã thử sử dụng // v9: Hình ảnh/sẽ hoạt động.

Do thư viện ColdFusion XPath triển khai, không có cách nào để đặt bối cảnh không gian tên tùy ý trong khi bạn thực hiện tìm kiếm; bạn bị giới hạn trong các không gian tên được khai báo ở gốc của tài liệu (và chúng được đổ vào không gian tên mặc định mà XPath có thể tìm kiếm), do đó cho phép bạn thực hiện tìm kiếm bằng cách sử dụng các bí danh không gian tên như // v9: Image /. Điều này xảy ra khi bạn tìm hiểu sâu hơn về XML, các vùng tên mới sẽ được giới thiệu.

NGUỒN: Specify xmlns namespaces in an XPath Search

+0

Đã xảy ra lỗi khi tìm kiếm tài liệu XML. Tiền tố phải giải quyết thành không gian tên: –

+0

báo giá. "Khai báo tài liệu gốc XML (bao gồm cả không gian tên v9) ..." .. Đó là cái gì ?? O.o –

+0

Hãy tiếp tục và cập nhật câu hỏi ban đầu bằng tài liệu XML hoàn chỉnh của bạn. Tôi có nghi ngờ lén lút rằng không gian tên v9 không được khai báo đúng/đúng vị trí trong tài liệu - nếu bạn không biết đó là gì, hãy đăng tài liệu ENTIRE xml, từ trên xuống dưới. –

2

Trong hầu hết các trường XPath vấn đề này được giải quyết bằng cách đăng ký namespace URI với một tiền tố tùy ý trong ngôn ngữ sở tại, nhưng tôi không thấy bất kỳ thông tin liên quan đến điều này trong the XMLSearch docs (và Google isn 't nhiều giúp đỡ, hoặc là).

Sau đây công việc xung quanh sẽ giúp trong khi chờ đợi:

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

này chọn image yếu tố từ bất kỳ không gian tên (hoặc không).

Hoặc, cụ thể hơn (như trong câu trả lời @ Shawn):

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

Lưu ý, tuy nhiên, điều này sẽ hoàn toàn không cần thiết, đưa ra một số cách để đăng ký tên miền không gian với động cơ XPath. Ví dụ, hãy xem xét hoàn thành ví dụ Java này:

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() + "]"); 
} 

Output:

[HUGE STUFF!!!] 

Mã này liên kết các tiền tố myName với namespace URI http://fedex.com/ws/ship/v9. biểu thức sau có thể tham khảo các nút trong namespace rằng việc sử dụng tên tiền tố tùy tiện chọn:

//myName:Image 

Người ta sẽ đoán rằng ColdFusion hỗ trợ chức năng tương tự, nhưng tôi đã không thể tìm thấy nó trong các tài liệu. Tuy nhiên, nếu chức năng như vậy không tồn tại, thì đây là giới hạn của Coldfusion.Đặc biệt, nó không liên quan gì đến XPath hoặc trong đó trong tài liệu nguồn khai báo không gian tên xuất hiện.

Các vấn đề liên quan