Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
- From: "Anthony Jones" <Ant@xxxxxxxxxxxxxxxx>
- Date: Fri, 12 Jan 2007 10:09:36 -0000
"Jon L" <not_putting@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8c4dq25m0qf03qso8b285ojku10a73pvhh@xxxxxxxxxx
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
Here is code I use to receive an XML post:-
Dim oDOM: Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
oDOM.async = False
oDOM.load Request
'Assert XML loaded
If oDOM.parseError.number <> 0 Then
'Exception code here
'End response
End If
' Processing of XML document can continue
A couple of other things:-
Don't use 'Microsoft.XMLDOM' since there's no way to be sure what you are
going to get, use a version specific ProgID instead. As above.
Null in VBScript is not equivalent to a Null object pointer which is instead
called Nothing VB speak.
News==----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption=----
.
- References:
- Prev by Date: Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
- Next by Date: aspsmartupload.dll 3.2+ ?
- Previous by thread: Re: ASP Coding Problem, XMLDOM-related (or just language-related!)
- Next by thread: aspsmartupload.dll 3.2+ ?
- Index(es):
Relevant Pages
|