Altova Mailing List Archives

XMl error: Namespace Manager or XsltContext needed.

From: XMLnewbieUrgentplshelp@-----------.---------.---
Date: 2/16/2006 7:33:00 AM
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it 
verifies the login information it should display the SessionID and enable 
some button . I appreciate your help and thanku in advance 

When I run the pgm , I get the error:
Can't parse login information. Namespace Manager or XsltContext needed. This 
query has a prefix, variable or userdefined function.

I have added the Try-catch in all my functions. In ParseLoginResponse 
function, it catches the above exception.

I am inclding all the functions I am using below:

Private Function SendXmlRequest(ByRef xml As String)


            Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl)

            ' Instantiate an XmlDocument object to avoid NullReference 

            Dim xmlDoc As XmlDocument

            xmlDoc = New System.Xml.XmlDocument

            'System.Xml.XmlDocument(xmldoc = New System.Xml.XmlDocument)

            'Dim xmlDoc As XmlDocument = Nothing

            'Dim xmlReader As XmlTextReader

            'xmlReader = Nothing

            xmpRequest.Method = "POST"

            xmpRequest.KeepAlive = True

            xmpRequest.ContentType = "text/xml"

            Dim writer As StreamWriter

            writer = New StreamWriter(xmpRequest.GetRequestStream())



            'Send the request and get the response

            Dim HttpWResponse As HttpWebResponse = 
CType(xmpRequest.GetResponse(), HttpWebResponse)

            'Console.WriteLine("before sending status")

            'Get the status and the headers

            Dim iStatCode As Integer = HttpWResponse.StatusCode

            Dim sStatus As String = iStatCode.ToString()

            Console.WriteLine("Status: {0} {1}", sStatus, 

            Console.WriteLine("Request Headers:")


            Console.WriteLine("Response Headers:")



            If Not HttpWResponse Is Nothing Then

                Dim XmlRead = New 

                'Dim xmlDoc As XmlDocument

                'xmlDoc = New XmlDocument

                'Dim xmlDoc = New XmlDocument


                Return xmlDoc


                Console.WriteLine("try again")


            End If

            'Get the response stream

            Dim strm As Stream = HttpWResponse.GetResponseStream()

            'Read the Response stream

            Dim encode As Encoding = 

            Dim sr As New StreamReader(strm, encode)

            Console.WriteLine("Response: {0}", sr.ReadToEnd())


            'new feb13

            'Dim doc As New XmlDocument






            'Read the response stream

            'Dim sr As StreamReader = New StreamReader(strm)

            'Dim sText As String = sr.ReadToEnd()

            'Console.WriteLine("Response: {0}", sText)


            '???Close the stream



            'Clean up

            'xmpRequest = Nothing

            'HttpWResponse = Nothing

            'MyCredentialCache = Nothing

            'myCred = Nothing

            'strm = Nothing

            'sr = Nothing



            'If sStatus = 200 Then

            'The Http Request/Response was successful, now we need to check 
the XML that was returned for errors

            'If Not RequestHasErrrors(xmpRequest.responseRext) Then

            'The overall request was successful so begin to parse the 
response XML 


            'SendXmlRequest = xmpRequest.responseXml

            'End If




            'End If

                       'End If


            'Call MsgBox("There was an error.  ReadyState = " & 

            'End If



        Catch ex As NullReferenceException


            MsgBox("Can't Request page" & vbCrLf & ex.Message)


        End Try


    End Function


    Private Function RequestHasErrors(ByRef xml As String) As Boolean

        ' Check for the high level error Xml in any response before

        ' trying to parse the results.

        If InStr(xml, "<Response><Error>") >= 1 Then

            RequestHasErrors = True

        End If

    End Function


    Private Function ParseLoginResponse(ByRef loginDom As XmlDocument) As 

        ' See if the login was successful.  If so, get the SessionID.

        ' Otherwise, log the error.



            ParseLoginResponse = False


            ' Setup the Dom to use XPath queries and also setup

            ' an Xml namespace prefix for use in the XPath queries.

            'Call loginDom.setProperty("SelectionLanguage", "XPath")


            Dim filterDoc As New XmlDocument



            'Instantiate an XmlNamespaceManager object

            'Dim nsmgr As XmlNamespaceManager

            'nsmgr = New XmlNamespaceManager(filterDoc.NameTable)


            'Add the namespaces used in books.xml to the XmlNamespaceManager.

            'nsmgr.AddNamespace("SelectionLanguage", "XPath")


"xmlns:ns='urn:schemas -tms:LoginResponse'")


            Dim node As XmlNode

            node = loginDom.SelectSingleNode("ns:LoginResponse/ns:Status")

            'node = New XmlDocument


            If node.Value = "Success" Then

                ' The login was 100% successful so get the SessionID.


                'new Feb 14

                'If node Is Nothing Then


                'for testing

                Console.WriteLine("Login successful: " & node.Value)

                node = 



                'Dim resultImport As XmlNode

                'resultImport = filterDoc.ImportNode(node, True)


                'Return True

                'g_SessionID = node.Value

                ParseLoginResponse = True

                'Console.WriteLine("Login successful: " & node.Value)






                'The login was not 100% successful

                node = 

                Console.WriteLine("Login unsuccessful: " & node.InnerText)




            End If


        Catch ex As Exception

            MsgBox("Can't parse login information" & vbCrLf & ex.Message)



        End Try


        'Return True


        ' The login was not 100% successful.

        'node = loginDom.SelectSingleNode("ns:LoginResponse/ns:SystemMessage")

        'Console.WriteLine("Login unsuccessful: " & node.text)

        'End If


        'loginDom = Nothing

        'node = Nothing

    End Function





End Class


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.