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> 

Aquí está mi respuesta SOAP, de mi servicio web.ColdFusion XmlSearch(): XPath con espacios de nombres

Quiero XmlSearch() para obtener el contenido <v9:image>.

¿Cuál es el XPath correcto? "// v9: image" ni "// image" ¡no funcionan!

Respuesta

13

El v9 espacio de nombre no está en la raíz, por lo que tendrá que modificar su sintaxis ligeramente a elementos de acceso en la sección v9 del documento XML:

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

Aquí, se ignora la declaración XML de v9, y se refieren explícitamente al espacio de nombres en la búsqueda XPath a través de namespace-uri(), y solicitan el valor del elemento con la función local-name().

Si se declaró v9 en la raíz (arriba en la parte superior) del documento XML, la antigua sintaxis de búsqueda de XPath que intentó usar // v9: Image/habría funcionado.

Debido a la implementación de la biblioteca ColdFusion XPath, no hay forma de establecer el contexto del espacio de nombres arbitrariamente mientras realiza su búsqueda; está limitado a los espacios de nombres que están declarados en la raíz del documento (y se vierten en el espacio de nombres predeterminado que XPath puede buscar), lo que le permite ejecutar una búsqueda utilizando alias de espacio de nombres como // v9: Image /. Esto se rompe cuando, a medida que se profundiza en el XML, se introducen nuevos espacios de nombres.

FUENTE: Specify xmlns namespaces in an XPath Search

+0

Ocurrió un error al buscar un documento XML. El prefijo debe resolverse en un espacio de nombre: –

+0

cita. "Declaración de documento raíz XML (incluido el espacio de nombres v9) ..." ... ¿Qué es eso? O.o –

+0

Continúe y actualice la pregunta original con su documento XML completo. Tengo la sospecha furtiva de que el espacio de nombres v9 no está declarado correctamente/en la posición correcta en el documento; si no sabe qué es eso, publique todo el documento xml, de arriba a abajo. –

2

En la mayoría de las implementaciones de XPath este problema se aborda mediante el registro de la URI de espacio con un prefijo arbitrario en la lengua de acogida, pero aún no hay información relacionada con esto en the XMLSearch docs (ISN y Google mucha ayuda, tampoco).

La siguiente solución alternativa debería ayudar en el ínterin:

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

Esta acción selecciona image elementos de cualquier espacio de nombres (o no).

O, más específicamente (como se muestra en la respuesta de Shawn @):

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

Tenga en cuenta, sin embargo, que esto sería totalmente innecesario, dado alguna manera de registrar el espacio de nombres con el motor de XPath. Por ejemplo, considere este ejemplo completo de 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() + "]"); 
} 

Salida:

[HUGE STUFF!!!] 

Este código asocia el prefijo myName con el URI de espacio http://fedex.com/ws/ship/v9. expresiones posteriores puede hacer referencia a nodos en ese espacio de nombres con el prefijo del nombre elegido arbitrariamente:

//myName:Image 

Uno podría suponer que ColdFusion soporta una funcionalidad similar, pero he podido encontrar en la documentación. Sin embargo, si tal funcionalidad no existe, entonces esta es una limitación de ColdFusion.En particular, no tiene nada que ver con XPath mismo o donde en el documento de origen aparece la declaración del espacio de nombres.

Cuestiones relacionadas