473,397 Members | 2,033 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,397 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 9554

"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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.