Help: How to use MSXML2.DOMDocument in ASP?

H

hb

Hi,

I need to use MSXML2.DOMDocument in my ASP page. The following is my code:

xml.asp:
=====
<%
dim sx
sx="<root><a>text1</a><b>text2</b></root>"
dim xd
set xd=Server.CreateObject("MSXML2.DOMDocument")
xd.loadXML(sx)
Response.write xd.hasChildNodes
%>

Somehow, xd.hasChildNodes return False, i.e. there is nothing in the xd. I
guess the
error was caused by missing the path of the MSXML2 library file. It seems
like the
code doesn't know where the MSXML2.DOMDocument is. But the code didn't
generate any error.

Would you please tell me what I did wrong here? What should I do to let the
code
know where the MSXML2 library file is?

Thank you

hb
 
B

Bob Barrows [MVP]

hb said:
Hi,

I need to use MSXML2.DOMDocument in my ASP page. The following is my
code:

xml.asp:
=====
<%
dim sx
sx="<root><a>text1</a><b>text2</b></root>"
dim xd
set xd=Server.CreateObject("MSXML2.DOMDocument")
xd.loadXML(sx)
Response.write xd.hasChildNodes
%>

What do you get when you do:
Response.Write xd.xml
?
Somehow, xd.hasChildNodes return False, i.e. there is nothing in the
xd. I guess the
error was caused by missing the path of the MSXML2 library file.

No, that's not the issue. First of all, CreatObject is not using the name of
a file: it is looking up the GUID for the class specified in the argument in
the Registry. If it can't find it, you will get a "cannot create object"
error. Since you are not getting that error, and since the loadXML method is
not generating an error, I think you can rule that out as the cause of your
problem.

I tried your code and it returned True for me, so I suspect there is a
version issue. Verify that you have MSXML 3.0 or higher installed on the web
server. You can get the latest version of the MSXML Parser at the Microsoft
website.

HTH,
Bob Barrows
 
H

hb

Thank you

hb
Bob Barrows said:
What do you get when you do:
Response.Write xd.xml
?


No, that's not the issue. First of all, CreatObject is not using the name of
a file: it is looking up the GUID for the class specified in the argument in
the Registry. If it can't find it, you will get a "cannot create object"
error. Since you are not getting that error, and since the loadXML method is
not generating an error, I think you can rule that out as the cause of your
problem.

I tried your code and it returned True for me, so I suspect there is a
version issue. Verify that you have MSXML 3.0 or higher installed on the web
server. You can get the latest version of the MSXML Parser at the Microsoft
website.

HTH,
Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 
B

Bob Barrows [MVP]

You're welcome. I hope that means your problem is solved.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top