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




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




----== 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: Design involving composition of inherited members.
    ... I am designing classes to work with an API. ... The API operates via XML ... Each API call involves sending a request and ... If the data packets' semantics are unique to each messageID, then each API method would know which particular serialization to use. ...
    (comp.object)
  • Re: Help: I cannot selectNodes with a simple XPath expression
    ... % [dom parse $xml] documentElement root ... So without an anonymous namespace, ...
    (comp.lang.tcl)
  • Re: IIS returns status code 200 even if XML is invalid
    ... ASMX requests are handled by ASP.NET ... when there is a problem with an XML being sent to the server ... The request is not being handled by the "designated method" which ... That HTTP 1.1 200 OK return code means the the HTTP request/connection ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: FAQ/FAQ notes site makeover
    ... VK suggested and XML procedure. ... Randy Webb wrote: ... easy to add a script-driven request generator with each topic having ... possibly that FAQ topics will not accomodate all and every accumulated ...
    (comp.lang.javascript)
  • Re: simple mock web service
    ... that does signal EOF at the end of the request. ... translated it to a String using the platform default character encoding. ... XML files have the encoding clearly indicated in the PI at the top ... change the wire representation of an XML document (such as a SOAP ...
    (comp.lang.java.help)