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)
Try
Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl)
' Instantiate an XmlDocument object to avoid NullReference
exception
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())
writer.Write(xml)
writer.Close()
'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,
HttpWResponse.StatusDescription.ToString())
Console.WriteLine("Request Headers:")
Console.WriteLine(xmpRequest)
Console.WriteLine("Response Headers:")
Console.WriteLine(HttpWResponse.Headers.ToString() )
'feb15
If Not HttpWResponse Is Nothing Then
Dim XmlRead = New
XmlTextReader(HttpWResponse.GetResponseStream())
'Dim xmlDoc As XmlDocument
'xmlDoc = New XmlDocument
'Dim xmlDoc = New XmlDocument
xmlDoc.Load(XmlRead)
Return xmlDoc
Else
Console.WriteLine("try again")
End If
'Get the response stream
Dim strm As Stream = HttpWResponse.GetResponseStream()
'Read the Response stream
Dim encode As Encoding =
System.Text.Encoding.GetEncoding("iso-8859-1")
Dim sr As New StreamReader(strm, encode)
Console.WriteLine("Response: {0}", sr.ReadToEnd())
sr.Close()
'new feb13
'Dim doc As New XmlDocument
'doc.Load(HttpWResponse.GetResponseStream())
'doc.Save(Console.Out)
'end
HttpWResponse.Close()
'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
'strm.Close()
'Clean up
'xmpRequest = Nothing
'HttpWResponse = Nothing
'MyCredentialCache = Nothing
'myCred = Nothing
'strm = Nothing
'sr = Nothing
'Feb14
'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
'Else
'End If
'End If
'Else
'Call MsgBox("There was an error. ReadyState = " &
xmpRequest.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
Boolean
' See if the login was successful. If so, get the SessionID.
' Otherwise, log the error.
Try
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")
'loginDom.setProperty("SelectionNamespaces",
"xmlns:ns='urn:schemas-tms:LoginResponse'")
Dim filterDoc As New XmlDocument
'Feb14
'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")
'nsmgr.AddNamespace("SelectionNamespaces",
"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 =
loginDom.SelectSingleNode("ns:LoginResponse/ns:SessionID")
'Dim resultImport As XmlNode
'resultImport = filterDoc.ImportNode(node, True)
'filterDoc.AppendChild(resultImport)
'Return True
'g_SessionID = node.Value
ParseLoginResponse = True
'Console.WriteLine("Login successful: " & node.Value)
'Feb14
Else
'The login was not 100% successful
node =
loginDom.SelectSingleNode("ns:LoginResponse/ns:SystemMessage")
Console.WriteLine("Login unsuccessful: " & node.InnerText)
End If
Catch ex As Exception
MsgBox("Can't parse login information" & vbCrLf & ex.Message)
End Try
'Feb13()
'Return True
'Else
' The login was not 100% successful.
'node = loginDom.SelectSingleNode("ns:LoginResponse/ns:SystemMessage")
'Console.WriteLine("Login unsuccessful: " & node.text)
'End If
'Feb13
'loginDom = Nothing
'node = Nothing
End Function
End Class 4 4082
Use the overload of SelectSingleNode that takes the namespace manager that
you set up.
"XML newbie: Urgent pls help!"
<XM********************@discussions.microsoft.co m> wrote in message
news:FD**********************************@microsof t.com... 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)
Try
Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl)
' Instantiate an XmlDocument object to avoid NullReference exception
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())
writer.Write(xml)
writer.Close()
'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, HttpWResponse.StatusDescription.ToString())
Console.WriteLine("Request Headers:")
Console.WriteLine(xmpRequest)
Console.WriteLine("Response Headers:")
Console.WriteLine(HttpWResponse.Headers.ToString() )
'feb15
If Not HttpWResponse Is Nothing Then
Dim XmlRead = New XmlTextReader(HttpWResponse.GetResponseStream())
'Dim xmlDoc As XmlDocument
'xmlDoc = New XmlDocument
'Dim xmlDoc = New XmlDocument
xmlDoc.Load(XmlRead)
Return xmlDoc
Else
Console.WriteLine("try again") End If
'Get the response stream
Dim strm As Stream = HttpWResponse.GetResponseStream()
'Read the Response stream
Dim encode As Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")
Dim sr As New StreamReader(strm, encode)
Console.WriteLine("Response: {0}", sr.ReadToEnd())
sr.Close()
'new feb13
'Dim doc As New XmlDocument
'doc.Load(HttpWResponse.GetResponseStream())
'doc.Save(Console.Out) 'end
HttpWResponse.Close()
'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
'strm.Close() 'Clean up
'xmpRequest = Nothing
'HttpWResponse = Nothing
'MyCredentialCache = Nothing
'myCred = Nothing
'strm = Nothing
'sr = Nothing 'Feb14
'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 'Else 'End If
'End If
'Else
'Call MsgBox("There was an error. ReadyState = " & xmpRequest.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 Boolean
' See if the login was successful. If so, get the SessionID.
' Otherwise, log the error. Try
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")
'loginDom.setProperty("SelectionNamespaces", "xmlns:ns='urn:schemas-tms:LoginResponse'") Dim filterDoc As New XmlDocument 'Feb14
'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") 'nsmgr.AddNamespace("SelectionNamespaces", "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 = loginDom.SelectSingleNode("ns:LoginResponse/ns:SessionID")
'Dim resultImport As XmlNode
'resultImport = filterDoc.ImportNode(node, True)
'filterDoc.AppendChild(resultImport)
'Return True
'g_SessionID = node.Value
ParseLoginResponse = True
'Console.WriteLine("Login successful: " & node.Value)
'Feb14 Else
'The login was not 100% successful
node = loginDom.SelectSingleNode("ns:LoginResponse/ns:SystemMessage")
Console.WriteLine("Login unsuccessful: " & node.InnerText)
End If Catch ex As Exception
MsgBox("Can't parse login information" & vbCrLf & ex.Message)
End Try
'Feb13()
'Return True
'Else
' The login was not 100% successful.
'node = loginDom.SelectSingleNode("ns:LoginResponse/ns:SystemMessage")
'Console.WriteLine("Login unsuccessful: " & node.text)
'End If
'Feb13
'loginDom = Nothing
'node = Nothing
End Function End Class
Thanks for yur response. But, I didn't get it. Could u elaborate more on it.
"Nick Hounsome" wrote: Use the overload of SelectSingleNode that takes the namespace manager that you set up.
"XML newbie: Urgent pls help!" <XM********************@discussions.microsoft.co m> wrote in message news:FD**********************************@microsof t.com...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)
Try
Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl)
' Instantiate an XmlDocument object to avoid NullReference exception
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())
writer.Write(xml)
writer.Close()
'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, HttpWResponse.StatusDescription.ToString())
Console.WriteLine("Request Headers:")
Console.WriteLine(xmpRequest)
Console.WriteLine("Response Headers:")
Console.WriteLine(HttpWResponse.Headers.ToString() )
'feb15
If Not HttpWResponse Is Nothing Then
Dim XmlRead = New XmlTextReader(HttpWResponse.GetResponseStream())
'Dim xmlDoc As XmlDocument
'xmlDoc = New XmlDocument
'Dim xmlDoc = New XmlDocument
xmlDoc.Load(XmlRead)
Return xmlDoc
Else
Console.WriteLine("try again") End If
'Get the response stream
Dim strm As Stream = HttpWResponse.GetResponseStream()
'Read the Response stream
Dim encode As Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")
Dim sr As New StreamReader(strm, encode)
Console.WriteLine("Response: {0}", sr.ReadToEnd())
sr.Close()
'new feb13
'Dim doc As New XmlDocument
'doc.Load(HttpWResponse.GetResponseStream())
'doc.Save(Console.Out) 'end
HttpWResponse.Close()
'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
'strm.Close() 'Clean up
'xmpRequest = Nothing
'HttpWResponse = Nothing
'MyCredentialCache = Nothing
'myCred = Nothing
'strm = Nothing
'sr = Nothing 'Feb14
'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 'Else 'End If
'End If
'Else
'Call MsgBox("There was an error. ReadyState = " & xmpRequest.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 Boolean
' See if the login was successful. If so, get the SessionID.
' Otherwise, log the error. Try
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")
'loginDom.setProperty("SelectionNamespaces", "xmlns:ns='urn:schemas-tms:LoginResponse'") Dim filterDoc As New XmlDocument 'Feb14
'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") http://msdn.microsoft.com/library/de...nodetopic2.asp
You seem to have been part way there but you commented out the
XmlNameSpaceManager that you need to give as the second arg
"XML newbie: Urgent pls help!"
<XM********************@discussions.microsoft.co m> wrote in message
news:03**********************************@microsof t.com... Thanks for yur response. But, I didn't get it. Could u elaborate more on it.
"Nick Hounsome" wrote:
Use the overload of SelectSingleNode that takes the namespace manager that you set up.
"XML newbie: Urgent pls help!" <XM********************@discussions.microsoft.co m> wrote in message news:FD**********************************@microsof t.com... >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) > > Try > > > Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl) > > ' Instantiate an XmlDocument object to avoid NullReference > exception > > 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()) > > writer.Write(xml) > > writer.Close() > > > '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, > HttpWResponse.StatusDescription.ToString()) > > Console.WriteLine("Request Headers:") > > Console.WriteLine(xmpRequest) > > Console.WriteLine("Response Headers:") > > Console.WriteLine(HttpWResponse.Headers.ToString() ) > > > 'feb15 > > If Not HttpWResponse Is Nothing Then > > Dim XmlRead = New > XmlTextReader(HttpWResponse.GetResponseStream()) > > 'Dim xmlDoc As XmlDocument > > 'xmlDoc = New XmlDocument > > 'Dim xmlDoc = New XmlDocument > > xmlDoc.Load(XmlRead) > > Return xmlDoc > > > Else > > Console.WriteLine("try again") > > > > End If > > > 'Get the response stream > > Dim strm As Stream = HttpWResponse.GetResponseStream() > > > 'Read the Response stream > > Dim encode As Encoding = > System.Text.Encoding.GetEncoding("iso-8859-1") > > Dim sr As New StreamReader(strm, encode) > > Console.WriteLine("Response: {0}", sr.ReadToEnd()) > > sr.Close() > > 'new feb13 > > 'Dim doc As New XmlDocument > > 'doc.Load(HttpWResponse.GetResponseStream()) > > 'doc.Save(Console.Out) > > > > 'end > > HttpWResponse.Close() > > > '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 > > 'strm.Close() > > > > 'Clean up > > 'xmpRequest = Nothing > > 'HttpWResponse = Nothing > > 'MyCredentialCache = Nothing > > 'myCred = Nothing > > 'strm = Nothing > > 'sr = Nothing > > > > 'Feb14 > > '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 > > > > 'Else > > > > 'End If > > > 'End If > > 'Else > > 'Call MsgBox("There was an error. ReadyState = " & > xmpRequest.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 > Boolean > > ' See if the login was successful. If so, get the SessionID. > > ' Otherwise, log the error. > > > > Try > > > 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") > > 'loginDom.setProperty("SelectionNamespaces", > "xmlns:ns='urn:schemas-tms:LoginResponse'") > > > > Dim filterDoc As New XmlDocument > > > > 'Feb14 > > '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") > > >
Thanks a lot for your quick and correct response . I appreciate it by
my heart.God bless u.
I fixed the error by:
Dim nsmgr As XmlNamespaceManager
nsmgr = New XmlNamespaceManager(filterDoc.NameTable)
msmgr.AddNamespace("ns", "urn:schemas -tms:LoginResponse")
loginDom.SelectSingleNode("ns:LoginResponse/ns:Status", nsmgr
Now, when I run my program, I don't get that error, but another: "Can't
parse Login information. Object reference not set to an instance of an
object".
Since, I have the exception"Can't parse Login information", in
ParseLoginResponse function, but I have noticed, when I compile the program,
I get the warning" Function SendXmlRequest doesn't return a value on all code
paths. A NullReference exception could occur at runtime'. Do u think, I am
getting the above error due to
"SendXmlRequest function", if yes/no how should I fix it.
Once again, I appreciate and thankyou in advance for your help.God bless u.
"Nick Hounsome" wrote: http://msdn.microsoft.com/library/de...nodetopic2.asp
You seem to have been part way there but you commented out the XmlNameSpaceManager that you need to give as the second arg
"XML newbie: Urgent pls help!" <XM********************@discussions.microsoft.co m> wrote in message news:03**********************************@microsof t.com... Thanks for yur response. But, I didn't get it. Could u elaborate more on it.
"Nick Hounsome" wrote:
Use the overload of SelectSingleNode that takes the namespace manager that you set up.
"XML newbie: Urgent pls help!" <XM********************@discussions.microsoft.co m> wrote in message news:FD**********************************@microsof t.com... >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) > > Try > > > Dim xmpRequest As HttpWebRequest = WebRequest.Create(XmpUrl) > > ' Instantiate an XmlDocument object to avoid NullReference > exception > > 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()) > > writer.Write(xml) > > writer.Close() > > > '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, > HttpWResponse.StatusDescription.ToString()) > > Console.WriteLine("Request Headers:") > > Console.WriteLine(xmpRequest) > > Console.WriteLine("Response Headers:") > > Console.WriteLine(HttpWResponse.Headers.ToString() ) > > > 'feb15 > > If Not HttpWResponse Is Nothing Then > > Dim XmlRead = New > XmlTextReader(HttpWResponse.GetResponseStream()) > > 'Dim xmlDoc As XmlDocument > > 'xmlDoc = New XmlDocument > > 'Dim xmlDoc = New XmlDocument > > xmlDoc.Load(XmlRead) > > Return xmlDoc > > > Else > > Console.WriteLine("try again") > > > > End If > > > 'Get the response stream > > Dim strm As Stream = HttpWResponse.GetResponseStream() > > > 'Read the Response stream > > Dim encode As Encoding = > System.Text.Encoding.GetEncoding("iso-8859-1") > > Dim sr As New StreamReader(strm, encode) > > Console.WriteLine("Response: {0}", sr.ReadToEnd()) > > sr.Close() > > 'new feb13 > > 'Dim doc As New XmlDocument > > 'doc.Load(HttpWResponse.GetResponseStream()) > > 'doc.Save(Console.Out) > > > > 'end > > HttpWResponse.Close() > > > '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 > > 'strm.Close() > > > > 'Clean up > > 'xmpRequest = Nothing > > 'HttpWResponse = Nothing > > 'MyCredentialCache = Nothing > > 'myCred = Nothing > > 'strm = Nothing > > 'sr = Nothing > > > > 'Feb14 > > '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 > > > > 'Else > > > > 'End If > > > 'End If > > 'Else > > 'Call MsgBox("There was an error. ReadyState = " & > xmpRequest.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 > Boolean > > ' See if the login was successful. If so, get the SessionID. > > ' Otherwise, log the error. > > > > Try > > > 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") > > 'loginDom.setProperty("SelectionNamespaces", > "xmlns:ns='urn:schemas-tms:LoginResponse'") > > > > Dim filterDoc As New XmlDocument > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Leonard T. Armstrong |
last post by:
I have an XML document that is structured similarly to the following
generalization:
<?xml version="1.0" encoding="UTF-8"?>
<A xmlns="urn:aaa-aaa-aaa:a-part">
<B>
<C...
|
by: Mike Dickens |
last post by:
hi,
i'm sure this has come up before but havn't managed to find an answer.
if i have the following xslt
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet method="xml" version="1.0"...
|
by: David Blickstein |
last post by:
I have an application where I have a shared "method" of selecting a nodeset.
The method currently is duplicated everywhere it is needed but I'd like that
code to be shared. The method also...
|
by: Kevin Newman |
last post by:
I've been toying with a namespace manager, and wanted to get some input.
So what do you think?
if (typeof com == 'undefined') var com = {};
if (!com.unFocus) com.unFocus = {};
...
|
by: Rick |
last post by:
I have an XML document that is generated from Infopath, I need to change
the value of a namespace that is defined in a node in the form:
<xsf:xDocumentClass "xmlns:my=valuehere">.
when i navigate...
|
by: Alpha |
last post by:
I created the following code in my C# program but it's giving me error
message at run time of :
XML.XPATH.XPATHEXCEPTION : Namespace Manager or XSLTContext needed. This
query has a prefix,...
|
by: XML newbie: Urgent pls help! |
last post by:
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...
|
by: Andy Fish |
last post by:
hi,
I have an XSLT which is producing XML output.
many of the nodes in the output tree contain namespace declarations for
namespaces that are used in the source document even though they are...
|
by: Dormilich |
last post by:
Hi,
I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means:
Error:
Fatal error: Can't use method return value in write context in "output.php" on...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |