473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Parsing XML messgae in VB.Net

When I try to parse: I get the following error message:

Unable to cast COM object of type
'Microsoft.SqlServer.MSXML6.DOMDocumentClass' to interface type
'MSXML2.ServerXMLHTTP40'. This operation failed because the QueryInterface
call on the COM component for the interface with IID
'{2E01311B-C322-4B0A-BD77-B90CFDC8DCE7}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."}

This is my code:

Private Sub cmdLogin_Click()
Dim loginXml As String
Dim loginResponse As MSXML2.DOMDocument40

loginXml = "<?xml version='1.0' encoding='ISO-8859-1'?>" & _
"<Login xmlns=""urn:schemas-tms:Login"">" & _
"<CustomerName>Test Closet</CustomerName>" & _
"<UserName>test</UserName>" & _
"<Password>none</Password>" & _
"</Login>"

loginResponse = SendXmlRequest(loginXml)

If Not loginResponse Is Nothing Then
If ParseLoginResponse(loginResponse) Then
cmdQueryAssetList.Enabled = True
End If
Else
Console.WriteLine("Login request failed.")
End If
End Sub

Private Function SendXmlRequest(ByRef xml As String) As MSXML2.DOMDocument40
Dim xmpRequest As MSXML2.ServerXMLHTTP40

xmpRequest = New MSXML2.ServerXMLHTTP40

' Set known timeout values so we have more control over our request.
Call xmpRequest.setTimeouts(10000&, 10000&, 30000&, 30000&)

' Open the Xmp Url for a Post operation and make the call synchronously.
Call xmpRequest.open("POST", XmpUrl, False)

' Set the necessary Http headers.
Call xmpRequest.setRequestHeader("Accept", "text/html, text/plain")
Call xmpRequest.setRequestHeader("User-Agent", "Custom App Name v1.0")
Call xmpRequest.setRequestHeader("Content-Type", "text/xml")

Call xmpRequest.send(xml)

' If the request times out, it throws an error, but we can simply check
the readyState
On Error Resume Next

If xmpRequest.readyState = 4 Then
' Turn error handling back on.
On Error GoTo 0

' The Http request was completed. However, this does not mean
' that it was necessarily successful. A successful Http response
' will have a Status Code of 200.
If xmpRequest.Status = 200 Then
' The Http request/response was successful, now we
' need to check the Xml that was returned for any errors.
If Not RequestHasErrors(xmpRequest.responseText) Then
' The overall request was successful so we can begin
' to parse the response Xml as necessary.
SendXmlRequest = xmpRequest.responseXML
End If
Else
' There was an Http error.
Console.WriteLine("Status Code: " & xmpRequest.Status)
Console.WriteLine("Status Text: " & xmpRequest.statusText)
Console.WriteLine("Response Text: " & xmpRequest.responseText)
End If
Else
Call MsgBox("There was an error. ReadyState = " &
xmpRequest.readyState)
End If
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 MSXML2.DOMDocument40)
As Boolean
' 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")
Call loginDom.setProperty("SelectionNamespaces",
"xmlns:ns='urn:schemas-tms:LoginResponse'")

Dim node As MSXML2.IXMLDOMNode

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

If node.Text = "Success" Then
' The login was 100% successful so get the SessionID.
node = loginDom.selectSingleNode("ns:LoginResponse/ns:SessionID")
g_SessionID = node.Text

ParseLoginResponse = True
Else
' 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

Private Sub cmdQueryAssetList_Click()
Dim queryAssetListXml As String
Dim queryAssetListResponse As MSXML2.DOMDocument40

queryAssetListXml = "<?xml version='1.0' encoding='ISO-8859-1'?>" & _
"<QueryAssetList2
xmlns=""urn:schemas-tms:QueryAssetList2"">" & _
"<SessionID>" & g_SessionID & "</SessionID>" & _
"</QueryAssetList2>"

queryAssetListResponse = SendXmlRequest(queryAssetListXml)

If Not queryAssetListResponse Is Nothing Then
Call ParseQueryAssetListResponse(queryAssetListResponse )
Else
Console.WriteLine("Query Asset List failed.")
End If
End Sub

Private Sub ParseQueryAssetListResponse(ByRef assetListDom As
MSXML2.DOMDocument40)
' Setup the Dom to use XPath queries and also setup
' an Xml namespace prefix for use in the XPath queries.
Call assetListDom.setProperty("SelectionLanguage", "XPath")
Call assetListDom.setProperty("SelectionNamespaces",
"xmlns:ns='urn:schemas-tms:QueryAssetList2'")

Console.WriteLine(assetListDom.xml)

Dim organizations As MSXML2.IXMLDOMNodeList
Dim org As MSXML2.IXMLDOMNode
Dim assets As MSXML2.IXMLDOMNodeList
Dim asset As MSXML2.IXMLDOMNode

organizations =
assetListDom.selectNodes("ns:QueryAssetList2/ns:Organization")

For Each org In organizations
Console.WriteLine(org.Attributes.getNamedItem("Nam e").Text)
assets = org.selectNodes("ns:AssetList/ns:Asset")

For Each asset In assets
Console.WriteLine(" " &
asset.Attributes.getNamedItem("ID").Text)
Next
Next
End Sub

Feb 8 '06 #1
0 4652

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Fire Juggler | last post by:
Hi, in a php script i'm writing, i want to set $email=fire_juggler_03@hotmail.com.nospam but it doesn't like it. How should i write the underscores? because i know you have to \' for apostrophes....
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.