Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i had xml like this
i want to get last shipmentevent node details using namespacemanager

XML
<?xml version="1.0" encoding="UTF-8"?>
<req:TrackingResponse xmlns:req="http://someurl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://someurl TrackingResponse.xsd">


XML
<AWBInfo>
    <AWBNumber>1234567895</AWBNumber>
    <Status>
      <ActionStatus>success</ActionStatus>
    </Status>
    <ShipmentInfo>
      <OriginServiceArea/>
      <DestinationServiceArea/>
      <ShipperName/>
      <ConsigneeName/>
      <ShipmentDate/>
      <DlvyNotificationFlag>N</DlvyNotificationFlag>
      <ShipmentEvent>
        <Date>2015-02-19</Date>
        <Time>15:21:00</Time>
        <ServiceEvent>
          <EventCode>CC</EventCode>
          <Description>Awaiting collection by recipient as requested</Description>
        </ServiceEvent>
        <Signatory/>
        <ServiceArea>
          <ServiceAreaCode>MAD</ServiceAreaCode>
          <Description>MADRID - SPAIN</Description>
        </ServiceArea>
      </ShipmentEvent>
      <ShipmentEvent>
        <Date>2015-02-19</Date>
        <Time>15:26:00</Time>
        <ServiceEvent>
          <EventCode>OK</EventCode>
          <Description>Delivered - Signed for by</Description>
        </ServiceEvent>
        <Signatory>MANUEL</Signatory>
        <ServiceArea>
          <ServiceAreaCode>MAD</ServiceAreaCode>
          <Description>MADRID - SPAIN</Description>
        </ServiceArea>
      </ShipmentEvent>
    </ShipmentInfo>
  </AWBInfo>


iam using code like this

shipmenteventdate = xmlDoc.SelectSingleNode("req:TrackingResponse/AWBInfo/ShipmentInfo/ShipmentEvent/Date", namespaceManager).InnerText;

but iam getting first shipmentevent node details i want last shipmentevent node details

Thanks
Posted
Updated 3-Apr-15 3:31am
v5

1 solution

You can select all nodes using SelectNodes, and then take the last:
C#
XmlNodeList nodes = xmlDoc.SelectNodes("req:TrackingResponse/AWBInfo/ShipmentInfo/ShipmentEvent/Date", namespaceManager);
XmlNode shipmenteventdate = nodes.Item(nodes.Count - 1);
 
Share this answer
 
Comments
Maciej Los 3-Apr-15 9:49am    
+5
Thomas Daniels 3-Apr-15 9:51am    
Thank you!
Member 10971356 3-Apr-15 10:26am    
Thank you Very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900