dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: What is correct use for of XmlNode.SelectSingleNode(string xpath) in C#?

  1. #1
    Join Date
    Oct 2009
    Posts
    14

    What is correct use for of XmlNode.SelectSingleNode(string xpath) in C#?

    There are two pieces of code I provided: XML and C# below. In the if (method == "AmazonTrackingRequest") statement in the C# code, I have a SelectSingleNode for Tracking Number and if you look at the XML code Tracking Number is the first field. I'm not sure how to code the next field in that XML which is City in C# like I did for the Tracking Number field and then so on with the next field State, and then Postal Code... Does that make sense? For example, the code that I have in C# for City:
    var city = doc.SelectNodes("City");, I'm not sure if that is correct and that is what I need assistance with. I am trying to pass these fields for Amazon Web Services.

    XML:
    Code:
    <PackageTrackingInfo> <TrackingNumber>123456789</TrackingNumber> <PackageDestinationLocation> <City>Seattle</City> <StateProvince>WA</StateProvince> <PostalCode>98107</PostalCode> <CountryCode>US</CountryCode> </PackageDestinationLocation> <PackageDeliveryDate> <ScheduledDeliveryDate>2004-09-15</ScheduledDeliveryDate>
    </PackageTrackingInfo>
    C#:
    Code:
    public string ProcessXML(string xmlRequest)
            {
                XmlDocument rsp = null;
                Saia.Presentation.Website.SaiaSecure.WebService.Shipment.Response response = new Saia.Presentation.Website.SaiaSecure.WebService.Shipment.Response();
                string testMode = "";
    
                try
                {
                    if (bool.Parse(WebConfigurationManager.AppSettings["Debug"]) == true)
                        File.WriteAllText("c:\\temp\\" + DateTime.Now.ToString("MMddyyy_HHmmss") + ".xml", xmlRequest);
                    // Determine Method to Call
                    XmlDocument doc = new XmlDocument();
                    doc.XmlResolver = null;
                    doc.LoadXml(xmlRequest);
    
                    string method = doc.FirstChild.Name;
    
                    if (method.ToLower() == "xml")
                    {
                        method = doc.FirstChild.NextSibling.Name;
                    }
    
                    if (method == "AmazonTrackingRequest")
                    {
                        Saia.Data.General.Shipment prc = new Data.General.Shipment();
                        string pronum = doc.FirstChild.SelectSingleNode("TrackingNumber").InnerText;
                        prc.GetByProNumber(decimal.Parse(pronum));
                        var city = doc.SelectNodes("City");
                        var state = doc.SelectNodes("State");
                        var postcode = doc.SelectSingleNode("PostalCode");
                        //string city = doc.SelectNodes("City");
                        //string state = doc.SelectNodes("State").ToString();
                        //string postcode = doc.SelectSingleNode("PostalCode").InnerText;
                        //string country = doc.SelectSingleNode("CountryCode").InnerText;
    
    
    
    
    
                        rsp = new XmlDocument();
    
                    }
    
                }
                catch (CodeException e)
                {
    
    
                    Core.Framework.Debug.CodeException(xmlRequest, e);
                }
                catch (Exception e)
                {
    
                    Core.Framework.Debug.Exception(xmlRequest, e);
                }
    
                return rsp.InnerXml;
            }
        }
    }

  2. #2
    Join Date
    Jan 2017
    Location
    Coimbatore, India
    Posts
    106
    Hello mldardy,
    You wouldnt get much help with c# here. We can help you with web based technologies only

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center