Solved

MSXML2.DOMDocument & ASP in IE

Posted on 2002-05-29
6
873 Views
Last Modified: 2010-05-18
Dear all,

I've a problem about the use of MSXML2.DOMDocument by ASP in IE.

When I develop a dll file by VB and call the function f_foo(strXML) by ASP in IE, there is an error occurred at point 1.  

========== VB Side ================
'dll : COM_Task.dll
'Class Module : clsTaskUpd
Public Function f_foo(ByVal v_strXML) As String
 On Error GoTo lblErrHandler
 Dim strTemp As String
 Dim objDOM As MSXML2.DOMDocument

 Set objDOM = New MSXML2.DOMDocument
 objDOM.loadXML v_strXML

 '*** point 1 ***
 With objDOM.documentElement.childNodes.Item(0).childNodes
 '*** point 2 ***
    strTemp = .Item(COL_RECSTS).Text
 End With

 f_foo = strDate

lblErrHandler:
    Err.Raise Err.Number
Exit Function


========== ASP Side ================
Sub pp_DBUpd()
 Dim strNew_LstUpdDte
 Dim comTask

 mstrReq = Request.Form      ' the xml text

 On Error Resume Next
 Err.clear

 Set comTask = CreateObject("COM_Task.clsTaskUpd")
 strNew_LstUpdDte = comTask.f_foo(mstrReq)
 Set comTask = Nothing

End Sub

The Err.Number is 91 and the corresponding description is "Object variable or With block variable not set", according to MSDN.

With the help of expert "b1xml2" in here, I try to change the program as follow but the problem still exists at point 1.

'**** point 1 ****
Set objElement = objDOM.documentElement.firstChild
'**** point 2 ****

OR

'**** point 1 ****
Set objNodeList = objDOM.documentElement.childNodes
'**** point 2 ****

It seems that MSXML2.DOMDocument cannot be referenced and the objDOM.parseError.errorCode is -1072896659.  But I can't find this error code in MSDN.

In fact, I try to write a small VB program to run the same dll and it functions correctly.  Just don't know why the dll call fail when using ASP with IE.

Please kindly give me some idea about my problem.

My development environemt is as follow :
Chinese Win2000 Professional
Chinese VB6 with SP 5
VB Reference : Microsoft XML, v3.0
Chinese IE 6.0
IIS 5.0

Thanks for your sincerely help.
0
Comment
Question by:alan_cheung
  • 3
  • 2
6 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 7042875
Try this:

Public Function f_foo(ByVal v_strXML) As String
On Error GoTo lblErrHandler
Dim strTemp As String
Dim objDOM As MSXML2.DOMDocument

Set objDOM = New MSXML2.DOMDocument
If objDOM.loadXML(v_strXML) Then  ' Change this

   '*** point 1 ***
   With objDOM.documentElement.childNodes.Item(0).childNodes
   '*** point 2 ***
      strTemp = .Item(COL_RECSTS).Text
   End With

   f_foo = strDate
Else                  <-- Add this
   Err.Raise vbObjectError, "Source Name", "XML did not load!"
End If

Exit Function           <--Add this

lblErrHandler:
   Err.Raise Err.Number
Exit Function
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7042883
Also, please maintain your open questions:

Questions Asked 19
Last 10 Grades Given A A A A A B A A A B  
Question Grading Record 13 Answers Graded / 13 Answers Received

Thanks,
Anthony
0
 

Author Comment

by:alan_cheung
ID: 7043590
I think I get the point of my problem.  As acperkins suggest, objDOM.loadXML(v_strXML) cannot load the parameter successfully and therefore raise the error.  After check the MSDN, it point out that loadXML()will work only with UTF-16 or UCS-2 encodings.  Therefore I think it doese not work in my Chinese system.

If my parameter is in the following format, is there any suggestion to load the parameter into the DOM in the Chinese system?

<list>
  <row>
    <RecSts>r</RecSts>
    <CreBy>ADMIN</CreBy>
    <CreDte_str>2002/05/17 22:50:08</CreDte_str>
    <LstUpdBy>ADMIN</LstUpdBy>
    <LstUpdDte_str>2002/05/30 10:34:51</LstUpdDte_str>
  </row>
</list>

I'm not sure if I can raise the above question follow by this thread.  If it is necessary to create a new thread with the above issue, please let me know.

Thanks for your kind attention.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7043709
I really could not say.  A couple of suggestions:
1. Change your code as follows:

If objDOM.loadXML(v_strXML) Then

  '*** point 1 ***
  With objDOM.documentElement.childNodes.Item(0).childNodes
  '*** point 2 ***
     strTemp = .Item(COL_RECSTS).Text
  End With

  f_foo = strDate
Else
  Err.Raise vbObjectError, "Source Name", "XML did not
load! Reason:" & objDOM.ParseError.reason <-- Change this line
End If

This may give you additional information.  Also, checkout all the other properties of the IXMLDOMParseError object.

2.  Take a look at the load method.  I believe it may not suffer the same limitation.  In other words, try loading the XML document from a file.

Hope this helps,
Anthony
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7044026
Try this:-
===========
Public Function f_foo(ByVal v_strXML,Optional ByVal bolEncoding = False) As String
On Error GoTo lblErrHandler
Dim strTemp As String
Dim objDOM As MSXML2.DOMDocument
Set objDOM = New MSXML2.DOMDocument
If bolEncoding Then v_strXML = "<?xml version='1.0' encoding='utf-8'?>" & v_strXML
If objDOM.loadXML(v_strXML) = False Then
 Err.Raise vbObjectError,"", objDOM.parseError.reason
End If

...
...


End Function

The point being you are putting in the encoding attribute via the loadXML method.



0
 

Author Comment

by:alan_cheung
ID: 7072297
Since acperkins comment help me to sport the source of problem.  Therefore I would like to give the point to him/her.  For the source and solution of my problem, please refer to qid 20308020 at XML.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question