473,236 Members | 1,307 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,236 software developers and data experts.

XML DOM/Null property problem (or just VBScript related(?!))

Hi,

I'm hoping someone can help me with this problem. I'm not sure whether
the problem lies with the software or with my understanding of the
language.

I'm using the Microsoft.XMLDOM object in an ASP page to read an
incoming XML post request and respond to it. Although the XMLDOM
object verifies the XML at a basic level, I want to make sure that the
request is in the correct format (as per the specification I have to
work to), as well as making sure that any XML at all was sent
successfully.

At the moment, I'm stuck at the point of just trying to make sure that
an XML request was sent at all. Here's the code I'm using.. (note that
I'm loading the XML from a file for ease-of-testing, but am giving a
bad filename so as to create the condition where the XML didn't load
successfully):

...<body>
<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Load ("C:\file_that_doesn't_exist.xml")
'xmlDoc.Load ("C:\InetPub\wwwroot\foo.xml")
If Not isNull(xmlDoc.documentElement) Then ' conditional
Response.Write xmlDoc.documentElement.nodeName
End If
%>
</body>..

From Microsoft's DOM reference, for the 'documentElement' property
(http://msdn2.microsoft.com/en-us/lib...s759095.aspx):

"The property is read/write. It returns an IXMLDOMElement that
represents the single element that represents the root of the XML
document tree. It returns Null if no root exists."

The problem is that documentElement doesn't seem to be returning Null,
or at least the method I'm using to evaluate it is drawing the wrong
conclusion, and so the Response.Write line is always executed, and
causes an 'Object required' error on that line. (Since, I assume, it's
attempting to call 'nodeName' on a null 'documentElement')

I've tried changing the condition to:

If xmlDoc.documentElement <Null Then

But this causes its own 'Object required' error. I've also tried
assigning the property to a variable using Set and testing the
variable, and other various variations but all to no avail!

Any comments/suggestions/corrections are extremely welcome, although
I'm looking for a way to make the conditional work as it should rather
than some other way of checking that the XML was sent properly, as I
have a more complete block of parsing code that runs into exactly the
same problem later on when checking for the existence of text values
for XML nodes.

Many thanks,

-Jon L
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 11 '07 #1
3 9528

"Jon L" <no*********@my.email.on.usenet.thankswrote in message
news:ee********************************@4ax.com...
Hi,

I'm hoping someone can help me with this problem. I'm not sure whether
the problem lies with the software or with my understanding of the
language.

I'm using the Microsoft.XMLDOM object in an ASP page to read an
incoming XML post request and respond to it. Although the XMLDOM
object verifies the XML at a basic level, I want to make sure that the
request is in the correct format (as per the specification I have to
work to), as well as making sure that any XML at all was sent
successfully.

At the moment, I'm stuck at the point of just trying to make sure that
an XML request was sent at all. Here's the code I'm using.. (note that
I'm loading the XML from a file for ease-of-testing, but am giving a
bad filename so as to create the condition where the XML didn't load
successfully):
That is a poor test case, you should go to the [minimal] effort of creating
a test client to post the XML sooner rather than later:

// jscript
var xml = new ActiveXObject("Microsoft.XMLDOM");
var req = new ActiveXObject("Microsoft.XMLHTTP");
xml.load(someFileName);
var Url = "http://...";
req.open("POST", Url, false);
req.send(xml);

..<body>
<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Load ("C:\file_that_doesn't_exist.xml")
'xmlDoc.Load ("C:\InetPub\wwwroot\foo.xml")
If Not isNull(xmlDoc.documentElement) Then ' conditional
Uninitialized objects in VBS are represented by the value Nothing, not Null.
The confusing thing can be that a variant can be Null, and then can later be
assigned an object reference, but that doesn't apply here, documentElement
is not a variant, it is always an object type. So the test is:

If Not xmlDoc.documentElement Is Nothing Then
To check structure I like to use DOMDocument.selectNode(). For example, to
check to see if an XML object is a persisted recordset I use:

if Not xml.selectNode("xml/rs:data") Is Nothing Then
-Mark

Response.Write xmlDoc.documentElement.nodeName
End If
%>
</body>..

From Microsoft's DOM reference, for the 'documentElement' property
(http://msdn2.microsoft.com/en-us/lib...s759095.aspx):

"The property is read/write. It returns an IXMLDOMElement that
represents the single element that represents the root of the XML
document tree. It returns Null if no root exists."

The problem is that documentElement doesn't seem to be returning Null,
or at least the method I'm using to evaluate it is drawing the wrong
conclusion, and so the Response.Write line is always executed, and
causes an 'Object required' error on that line. (Since, I assume, it's
attempting to call 'nodeName' on a null 'documentElement')

I've tried changing the condition to:

If xmlDoc.documentElement <Null Then

But this causes its own 'Object required' error. I've also tried
assigning the property to a variable using Set and testing the
variable, and other various variations but all to no avail!

Any comments/suggestions/corrections are extremely welcome, although
I'm looking for a way to make the conditional work as it should rather
than some other way of checking that the XML was sent properly, as I
have a more complete block of parsing code that runs into exactly the
same problem later on when checking for the existence of text values
for XML nodes.

Many thanks,

-Jon L
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption
=----

Jan 12 '07 #2
Jon L wrote:
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False

If xmlDoc.load("C:\file_that_doesn't_exist.xml") Then
' process loaded document here
Else
'check reason that XML was not loaded e.g.
Response.Write(xmlDoc.parseError.reason)
End If

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 12 '07 #3
Mark, agreed that this was a poor test case, but it was really just to
demonstrate the problem. I'm using cURL to post an XML file for proper
testing.

The info on Null/Nothing is exactly what I was looking for, thanks.
The "If Not .. Is Nothing" syntax is what I was missing, and fixes the
problem I was having nicely.

Cheers,

-Jon L

On Thu, 11 Jan 2007 22:48:56 -0800, "Mark J. McGinty"
<mm******@spamfromyou.comwrote:
>
"Jon L" <no*********@my.email.on.usenet.thankswrote in message
news:ee********************************@4ax.com.. .
>Hi,

I'm hoping someone can help me with this problem. I'm not sure whether
the problem lies with the software or with my understanding of the
language.

I'm using the Microsoft.XMLDOM object in an ASP page to read an
incoming XML post request and respond to it. Although the XMLDOM
object verifies the XML at a basic level, I want to make sure that the
request is in the correct format (as per the specification I have to
work to), as well as making sure that any XML at all was sent
successfully.

At the moment, I'm stuck at the point of just trying to make sure that
an XML request was sent at all. Here's the code I'm using.. (note that
I'm loading the XML from a file for ease-of-testing, but am giving a
bad filename so as to create the condition where the XML didn't load
successfully):

That is a poor test case, you should go to the [minimal] effort of creating
a test client to post the XML sooner rather than later:

// jscript
var xml = new ActiveXObject("Microsoft.XMLDOM");
var req = new ActiveXObject("Microsoft.XMLHTTP");
xml.load(someFileName);
var Url = "http://...";
req.open("POST", Url, false);
req.send(xml);

>..<body>
<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Load ("C:\file_that_doesn't_exist.xml")
'xmlDoc.Load ("C:\InetPub\wwwroot\foo.xml")
If Not isNull(xmlDoc.documentElement) Then ' conditional

Uninitialized objects in VBS are represented by the value Nothing, not Null.
The confusing thing can be that a variant can be Null, and then can later be
assigned an object reference, but that doesn't apply here, documentElement
is not a variant, it is always an object type. So the test is:

If Not xmlDoc.documentElement Is Nothing Then
To check structure I like to use DOMDocument.selectNode(). For example, to
check to see if an XML object is a persisted recordset I use:

if Not xml.selectNode("xml/rs:data") Is Nothing Then
-Mark

> Response.Write xmlDoc.documentElement.nodeName
End If
%>
</body>..

From Microsoft's DOM reference, for the 'documentElement' property
(http://msdn2.microsoft.com/en-us/lib...s759095.aspx):

"The property is read/write. It returns an IXMLDOMElement that
represents the single element that represents the root of the XML
document tree. It returns Null if no root exists."

The problem is that documentElement doesn't seem to be returning Null,
or at least the method I'm using to evaluate it is drawing the wrong
conclusion, and so the Response.Write line is always executed, and
causes an 'Object required' error on that line. (Since, I assume, it's
attempting to call 'nodeName' on a null 'documentElement')

I've tried changing the condition to:

If xmlDoc.documentElement <Null Then

But this causes its own 'Object required' error. I've also tried
assigning the property to a variable using Set and testing the
variable, and other various variations but all to no avail!

Any comments/suggestions/corrections are extremely welcome, although
I'm looking for a way to make the conditional work as it should rather
than some other way of checking that the XML was sent properly, as I
have a more complete block of parsing code that runs into exactly the
same problem later on when checking for the existence of text values
for XML nodes.

Many thanks,

-Jon L
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption
=----
---
Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy,
it deosn't mttaer in waht oredr the ltteers in a wrod
are, the olny iprmoetnt tihng is taht the frist and
lsat ltteer be at the rghit pclae. The rset can be
a total mses and you can sitll raed it wouthit porbelm.
Tihs is bcuseae the huamn mnid deos not raed ervey
lteter by istlef, but the wrod as a wlohe.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 13 '07 #4

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

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
21
by: Scott Townsend | last post by:
I have a form that I allow the user to use the ALT-S key to submit. I'd like to have just the S in the Submit button underlined, Is this possible? Thanks, Scott<-
1
by: | last post by:
I'm going a little crazy trying to learn how to use arrays as properties in VBScript classes. Hopefully someone can help. First, I can't figure out whether it's possible to iterate through the...
16
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this...
4
by: Peter Hemmingsen | last post by:
Hi, I have a dotnet object (implemented in mc++ and used in c#) which have a property called "Info". The Info property is also a dotnet object (implemented in mc++). In the constructor of the...
2
by: S. Lorétan | last post by:
Hello. I have some structs in different namespaces/classes/other structs and I sometime have to check if it contains something or not. myStruct == null doesn't work. I've currently done it...
9
by: Tony Girgenti | last post by:
Hello. I'm developing and testing a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2 computer. I'm using a web form. For a...
3
by: cmsimmers | last post by:
I'm trying to display the available space on a disk drive. This could be tricky if the user choose a drive on which they are limited to a quota. The "FreeSpace" property returns the total number...
4
by: Debbiedo | last post by:
I searched the groups and tried several approaches but still cannot find a solution. I have a table that has several hundred fields that may or may not need to be displayed in a report,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.