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



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



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 ... 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: parsing xml
    ... If I knew how, I would show you one of the XML files, ... In these cases read the data, text or xml property -- check the ... = vbCancel Then Exit Function ... Dim xmlDoc As New MSXML2.DOMDocument50 ...
    (microsoft.public.data.ado)
  • 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)

Loading