-1

when I a get the XML url from a recordset I get this error

Invalid procedure call or argument: 'xmlDOM.load'

Set xmlDOM = CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True

sql="select top 1 * from rss where id=12"
rs.open sql,objcon
if not rs.eof then
    response.write rs("url") 'This returns http://npps.ir/rss.aspx?c=25
    xmlDOM.Load(rs("url"))
end if
rs.close

But there is no error when I hardcode that url (however it returns false because the target url is not a valid XML):

xmlDOM.Load("http://npps.ir/rss.aspx?c=25")

As I read in documentation of MSXML2 the Load method will return true or false on the case of succes or fail. So why do I get that error and why there is no error when I hardcode the url?

Update:

when I used xmlDOM.Load(cstr(rs("url"))) I got no error. Isn't a recordset value a string itself?

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82

1 Answers1

2

So why do I get that error and why there is no error when I hardcode the url? ... Isn't a recordset value a string itself?

Depending upon your DB provider, rs("url") can return a Field object, which has additional properties like Name, Type, Value, Attributes, etc. Trying to rely on default properties and default collections can result in errors like these. It might be best to be explicit when working with OLE DB and ADO ODBC providers. For example, result = xmlDOM.Load(CStr(rs.Fields.Item("url").Value)) retrieves the Field object for the url item, grabs its Value property, then converts the Value to a Variant of subtype String for the xmlDOM.Load() call, and captures the result for subsequent validation.

BTW, If you are not interested in validating the XML, then try adding xmlDOM.resolveExternals = False and xmlDOM.validateOnParse = False before calling xmlDOM.Load(). Finally, if your environment uses a proxy server, be sure to run your script from a valid user context for proper proxy authentication. Otherwise, review the setProxy and setProxyCredentials methods of MSXML2.ServerXMLHTTP, instead. Worth a mention.

Hope this info helps.

leeharvey1
  • 1,316
  • 9
  • 14
  • Just like the [documentation says](https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/item-property-ado) for `.Item()` method - *"Returns an object reference."* – user692942 Mar 16 '20 at 13:06