Solved

MSXML2.DOMDocument & ASP in IE

Posted on 2002-05-29
6
870 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now