I am using Xpath to get a value but fails when the xml has an element of the form <ns0:PurchaseOrderSent xmlns:ns0="http://www.buylink.com.au"> </ns0:PurchaseOrderSent> BUT works when its of the form <ns0 xmlns:ns0="http://www.buylink.com.au"></ns0 >
Anyone see the issues? Is <ns0:PurchaseOrderSent.. valid XML element? FAILS <ns0:PurchaseOrderSent xmlns:ns0="http://www.buylink.com.au"> <DownloadPurchaseOrder> <PurchaseOrder> <Header DocType="PO" PoNo="2192" /> </PurchaseOrder> </DownloadPurchaseOrder> </ns0:PurchaseOrderSent> Function getXMLXpath(ByVal sXML As String) As String Dim myEncoder As New System.Text.ASCIIEncoding Dim bytes As Byte() = myEncoder.GetBytes(sXML) Dim ms As MemoryStream = New MemoryStream(bytes) Dim xpathDoc As XPathDocument Dim xmlNav As XPathNavigator Dim xmlNI As XPathNodeIterator xpathDoc = New XPathDocument(ms) xmlNav = xpathDoc.CreateNavigator() Try xmlNI = xmlNav.Select("/ns0:PurchaseOrderSent/DownloadPurchaseOrder/PurchaseOrder/He ader/@PoNo") //Excepytion Erros 'Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.' While (xmlNI.MoveNext()) Return xmlNI.Current.Value End While Catch ex As Exception End Try End Function WORKS <ns0 xmlns:ns0="http://www.buylink.com.au"> <DownloadPurchaseOrder> <PurchaseOrder> <Header DocType="PO" PoNo="2192" /> </PurchaseOrder> </DownloadPurchaseOrder> </ns0 > Function getXMLXpath(ByVal sXML As String) As String Dim myEncoder As New System.Text.ASCIIEncoding Dim bytes As Byte() = myEncoder.GetBytes(sXML) Dim ms As MemoryStream = New MemoryStream(bytes) Dim xpathDoc As XPathDocument Dim xmlNav As XPathNavigator Dim xmlNI As XPathNodeIterator xpathDoc = New XPathDocument(ms) xmlNav = xpathDoc.CreateNavigator() Try xmlNI = xmlNav.Select("/ns0/DownloadPurchaseOrder/PurchaseOrder/Header/@PoNo") While (xmlNI.MoveNext()) Return xmlNI.Current.Value 'Returns 2192 End While Catch ex As Exception End Try End Function Is your website being IntelliXperienced? <http://www.intellixperience.com/signup.aspx> | www.yougoingmyway.com ? regards Anthony (*12QWERNB*) Is your website being IntelliXperienced?