Reputation: 1655
I wish to write an XPath query to my XML Query Function. I am running into an issue primarily based in my lack of previous knowledge of anything XML and I've been forced into it a bit.
But let's say I have a text box with the following XML output, how would I pull the information from say the <State>
of the <ShipmentOrigin>
? Mind you, there are a few other instances of <State>
, so doing a full out search for <State>
won't work, it would have to be specifically focused on the <State>
within <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>
Upvotes: 1
Views: 32
Reputation: 52888
The answer depends on what's processing the XPath and whether or not you can bind a namespace to a prefix.
If you can bind the https://webservices.rrts.com/tracking/
namespace to a prefix (tr
for example), you could do something like this...
//tr:ShipmentOrigin/tr:State
If you are unable to bind the namespace to a prefix, you could use local-name()
...
//*[local-name()='ShipmentOrigin']/*[local-name()='State']
You could/should also use namespace-uri()
to make sure you're matching exactly what you're intending to match...
//*[namespace-uri()='https://webservices.rrts.com/tracking/' and local-name()='ShipmentOrigin']/*[namespace-uri()='https://webservices.rrts.com/tracking/' and local-name()='State']
Upvotes: 1