2017-10-02 6 views
1

私はXMLクエリ関数にXPathクエリを書きたいと思っています。私は主に何かXMLの以前の知識の私の欠如に基づいて問題に実行されていると私はそれに少し強制されてきた。XMLクエリのネームスペースとノード

ただし、次のXML出力のテキストボックスがあるとします。<ShipmentOrigin><State>という情報をどのように引き出すのですか?のいくつかの例がありますので、<State>の完全な検索は機能しません。具体的には<State><ShipmentOrigin>に集中する必要があります。

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <TrackViaPronumberAdvancedResponse xmlns="https://webservices.rrts.com/tracking/"> 
      <TrackViaPronumberAdvancedResult> 
       <ShipmentOrigin> 
        <Name>EXAMPLE</Name> 
        <Address1>EXAMPLE</Address1> 
        <Address2>EXAMPLE</Address2> 
        <City>EXAMPLE</City> 
        <State>EXAMPLE</State> 
        <PostalCode>EXAMPLE</PostalCode> 
       </ShipmentOrigin> 
       <ShipmentDestination> 
        <Name>EXAMPLE</Name> 
        <Address1>EXAMPLE</Address1> 
        <Address2/> 
        <City>EXAMPLE</City> 
        <State>EXAMPLE</State> 
        <PostalCode>EXAMPLE</PostalCode> 
       </ShipmentDestination> 
       <Details> 
        <Pronumber>EXAMPLE</Pronumber> 
        <PickupNumber/> 
        <CustomerNumber>EXAMPLE</CustomerNumber> 
        <BOLNumber/> 
        <PONumber>EXAMPLE</PONumber> 
        <Pieces>5</Pieces> 
        <Weight>214</Weight> 
        <AppointmentDate>9/20/2017</AppointmentDate> 
        <EstimatedDelivery>NA</EstimatedDelivery> 
        <DeliveredDate>9/20/2017</DeliveredDate> 
        <BillToNumber>5001868</BillToNumber> 
        <AppointmentTime>10:00 AM</AppointmentTime> 
        <ProjectedDeliveryDate>2017-09-25T00:00:00</ProjectedDeliveryDate> 
        <DeliveredTime/> 
        <HAWB/> 
       </Details> 

       <OriginTerminal> 
        <TerminalName>San Francisco</TerminalName> 
        <TerminalTollFreePhone>(877) 220-4582</TerminalTollFreePhone> 
       </OriginTerminal> 
       <Comments> 
        <ShipmentComment> 
         <CommentDate>09/14</CommentDate> 
         <ActivityCode>PU</ActivityCode> 
         <Comment>Shipment was picked up</Comment> 
         <StatusTime>12:03 AM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/25</CommentDate> 
         <ActivityCode>DUD</ActivityCode> 
         <Comment>Projected Delivery Date of 9/25/2017</Comment> 
         <StatusTime>12:03 AM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/16</CommentDate> 
         <ActivityCode>CLO</ActivityCode> 
         <Comment>Trailer Closed - ready for dispatch</Comment> 
         <StatusTime>2:00 AM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/17</CommentDate> 
         <ActivityCode>DSP</ActivityCode> 
         <Comment>Trailer dispatched to terminal</Comment> 
         <StatusTime>12:00 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/18</CommentDate> 
         <ActivityCode>ENR</ActivityCode> 
         <Comment>Trailer enroute: BRYAN, WY</Comment> 
         <StatusTime>3:02 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/19</CommentDate> 
         <ActivityCode>INV</ActivityCode> 
         <Comment>Invoice has been emailed</Comment> 
         <StatusTime>6:03 AM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/19</CommentDate> 
         <ActivityCode>ARX</ActivityCode> 
         <Comment>Trailer arrived at terminal in DENVER, CO</Comment> 
         <StatusTime>12:00 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/19</CommentDate> 
         <ActivityCode>UNL</ActivityCode> 
         <Comment>Trailer unloaded at terminal</Comment> 
         <StatusTime>12:01 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/19</CommentDate> 
         <ActivityCode>TRF</ActivityCode> 
         <Comment>Released to Delivery</Comment> 
         <StatusTime>5:00 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/20</CommentDate> 
         <ActivityCode>OFD</ActivityCode> 
         <Comment>Shipment out for delivery</Comment> 
         <StatusTime>12:00 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/20</CommentDate> 
         <ActivityCode>APT</ActivityCode> 
         <Comment>Appointment set for delivery to consignee on 9/20/2017</Comment> 
         <StatusTime>1:03 PM</StatusTime> 
        </ShipmentComment> 
        <ShipmentComment> 
         <CommentDate>09/20</CommentDate> 
         <ActivityCode>DED</ActivityCode> 
         <Comment>Shipment delivered to consignee</Comment> 
         <StatusTime>4:05 PM</StatusTime> 
        </ShipmentComment> 
       </Comments> 
       <BOLReceived>true</BOLReceived> 
       <PODReceived>true</PODReceived> 
       <InspectionAvailable>false</InspectionAvailable> 
      </TrackViaPronumberAdvancedResult> 
     </TrackViaPronumberAdvancedResponse> 
    </soap:Body> 
</soap:Envelope> 

答えて

1

答えはXPathの処理内容と名前空間を接頭辞にバインドできるかどうかによって異なります。

あなたは接頭辞(例えばtr)にhttps://webservices.rrts.com/tracking/名前空間をバインドすることができれば、あなたはこのような何かを行うことができ...

//tr:ShipmentOrigin/tr:State 

あなたは接頭辞に名前空間をバインドすることができない場合、あなたは可能性...

//*[local-name()='ShipmentOrigin']/*[local-name()='State'] 

あなたは/また、あなたが一致することを意図しているものを正確に一致していることを確認するnamespace-uri()を使用する必要がある可能性が... local-name()使用

//*[namespace-uri()='https://webservices.rrts.com/tracking/' and local-name()='ShipmentOrigin']/*[namespace-uri()='https://webservices.rrts.com/tracking/' and local-name()='State'] 
+0

またはXPath 2.0では、「// *:ShipmentOrigin/*:State' –

+0

@MichaelKay - 良い点。私がXPath 1.0を仮定した理由は不明です。 –

関連する問題