davearia Posted November 11, 2006 Posted November 11, 2006 Hi All, Hope your weekend is good. Here is some XML: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <placeOrder xmlns="http://tempuri.org/"> <dbsAPIRequest> <Header> <loginGUID>026b518c-6916-434a-85ba-88fedce62fac</loginGUID> <API_Version>1</API_Version> </Header> </dbsAPIRequest> </placeOrder> </soap:Body> </soap:Envelope> Here is part of my code that is trying to reach elements within the header node: Dim HeaderXMLNodelst As XmlNodeList = orders.SelectNodes("//Envelope/Body/placeOrder/dabsAPIRequest/Header") For Each HeaderXMLItem As XmlNode In HeaderXMLNodelst loginGUID = HeaderXMLItem.SelectSingleNode("CompanyGUID").InnerXml API_Version = Convert.ToInt32(HeaderXMLItem.SelectSingleNode("API_Version").InnerXml) Next The code does not error but fails to bring any values for loginGUID and API_Version . Any ideas? Cheers, Dave. Quote
MrPaul Posted November 23, 2006 Posted November 23, 2006 Namespaces in XPath Okay, firstly your XML contains the element dbsAPIRequest but your XPath contains dabsAPIRequest. Note the extra a. Besides that, namespaces must be declared in the XPath and then issued with a prefix. In this case your XPath might look something like: "//s:Envelope/s:Body/placeOrder/dbsAPIRequest/Header s http://schemas.xmlsoap.org/soap/envelope/" Here we define the prefix s to indicate the namespace http://schemas.xmlsoap.org/soap/envelope and prefix Envelope and Body with s. Note that the prefix used in the XPath need not match the prefix used in the XML. Good luck :cool: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.