Re: ASP Coding Problem, XMLDOM-related (or just language-related!)



That does it, thanks! the "If Not ... Is Nothing" syntax is what I was
missing.

Cheers,

-Jon L

On Fri, 12 Jan 2007 13:24:18 +1000, Dave <dave@xxxxxxxxxxx> wrote:

How about

<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
If xmlDoc.Load ("C:\foo.xml") Then
Response.Write xmlDoc.documentElement.nodeName

If Not xmlDoc.documentElement.firstChild is nothing Then ' check

Response.Write xmlDoc.documentElement.firstChild.nodeValue
End If
Else
Response.Write "Could not load the file"
End If
%>

David Bray
http://www - dot - brayworth - dot - com - dot - au
david - at - brayworth - dot - com - dot - au

/*
This email is but an indication and in no
way a complete and/or faithful statement.
*/

Jon L wrote:
Yes that does fix the immediate problem, removing the need to check
the documentElement property for Null at all, but not the problem that
I run into later in the parsing code which is of a similar nature.

To demonstrate this:

<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
If xmlDoc.Load ("C:\foo.xml") Then
Response.Write xmlDoc.documentElement.nodeName
If Not isNull(xmlDoc.documentElement.firstChild) Then ' check
Response.Write xmlDoc.documentElement.firstChild.nodeValue
End If
Else
Response.Write "Could not load the file"
End If
%>

------- foo.xml -------
<?xml version="1.0"?>
<foo></foo>
----- end foo.xml -----

The firstChild property for documentElement should return Null as per
http://msdn2.microsoft.com/en-us/library/ms753823.aspx, as the 'foo'
tag is empty, but execution of the code above sails past the line
marked 'check' to execute the next line and cause another 'Object
required' error. I have no idea why this happens, but I guess that
either the object isn't returning Null as promised, or the IsNull
function isn't the correct check to use here (although, again, I've
tried checking for equality with Null as well).

Any further insight welcome.

Cheers,

-Jon L

On Fri, 12 Jan 2007 09:37:08 +1000, Dave <dave@xxxxxxxxxxx> wrote:

shouldn't that be ...

..<body>
<%
Dim xmlDoc
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
if xmlDoc.Load ("C:\file_that_doesn't_exist.xml") then

'xmlDoc.Load ("C:\InetPub\wwwroot\foo.xml")
If Not isNull(xmlDoc.documentElement) Then ' conditional
Response.Write xmlDoc.documentElement.nodeName
End If
else
response.write "unable to load .."
end if

%>
</body>..
David Bray
http://www - dot - brayworth - dot - com - dot - au
david - at - brayworth - dot - com - dot - au

/*
This email is but an indication and in no
way a complete and/or faithful statement.
*/

Jon L wrote:
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/library/ms759095.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 =----


----== 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 =----


----== 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 =----
.



Relevant Pages

  • Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
    ... > Dim xmlDoc ... Set xmlDoc = Server.CreateObject ... The firstChild property for documentElement should return Null as per ... incoming XML post request and respond to it. ...
    (microsoft.public.inetserver.asp.components)
  • Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
    ... Dim xmlDoc ... Set xmlDoc = Server.CreateObject ... The firstChild property for documentElement should return Null as per ... incoming XML post request and respond to it. ...
    (microsoft.public.inetserver.asp.components)
  • Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
    ... > Dim xmlDoc ... incoming XML post request and respond to it. ... bad filename so as to create the condition where the XML didn't load ... The problem is that documentElement doesn't seem to be returning Null, ...
    (microsoft.public.inetserver.asp.components)
  • Re: WSH from vbs to js
    ... Here is correct code (both xml and vbs are changed, ... dim xmlDoc ... set xmlDoc = CreateObject ...
    (microsoft.public.scripting.wsh)
  • Re: Assigning Attributes
    ... The xml document is being loaded from a file. ... > retrieve from this xml string and assign to a variable. ... > Dim xmlDoc ...
    (microsoft.public.scripting.wsh)