Link to home
Start Free TrialLog in
Avatar of CIT_DEV
CIT_DEV

asked on

Issues with loading an XML document using .load method

I get the following error.

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'MSXML4.ServerXMLHTTP'

when i open the http://att.ws.com/UserXML.asp i get a properly formatted XML document. But when i try to load the using the URL, it errors out.

***********************************************************
The Code is as follows
***********************************************************

StrURL         = "http://att.ws.com/UserXML.asp"

Set xmlObj = CreateObject("Microsoft.FreethreadedXMLDOM")
xmlObj.SetProperty "ServerHTTPRequest", False
xmlObj.async = False
xmlObj.load  StrURL

'-----------------------------------------------------------------------
' Check XML document
'-----------------------------------------------------------------------
If Not xmlObj.ParseError = 0 Then
  Response.Write "<b>Error Code:</b> " & xmlObj.ParseError & "<br>"
  Response.Write "<b>Error Code:</b> " & xmlObj.ParseError.errorCode & "<br>"
  Response.Write "<b>Error Description:</b> " & xmlObj.ParseError.reason & "<br>"
  Response.Write "<b>Error File Position:</b> " & xmlObj.ParseError.filepos & "<br>"
  Response.Write "<b>Error Line:</b> " & xmlObj.ParseError.line & "<br>"
  Response.Write "<b>Error Line Position:</b> " & xmlObj.ParseError.linepos & "<br>"
  Response.Write "<b>Error URL pointing the loaded document</b> " & xmlObj.ParseError.url & "<br>"
  Response.Write "<b>Error Source Text:</b> " & xmlObj.ParseError.srcText & "<br>"
Else
  '-----------------------------------------------------------------------
  ' Send XML request - AT&T Extranet
  '-----------------------------------------------------------------------
  VendorURL      =      "https://stg-busweb01.attwireless.com/aps/PunchOutSetupRequestDispatch"
  Set XMLhttp = CreateObject("MSXML2.ServerXMLHTTP")
  XMLhttp.Open "POST", VendorURL, False
  XMLhttp.Send "requestMessage=" & xmlObj.xml
   
  '-----------------------------------------------------------------------
  ' Get server status
  '-----------------------------------------------------------------------
  Response.Write "<textarea rows=20 cols=100  id=textarea1 name=textarea1>" & xmlObj.xml  & "</textarea>"
  Response.Write "<br>"
  Response.Write "<b><font face=arial size=2>ATT Server Status:</b><br>"
  Response.Write "-----------------------------------------<br>"
  Response.Write "<b>Status (Value must be 200): </b>" & XMLhttp.status & "<br>"
  Response.Write "<b>ReadyState (Value must be 4): </b>" & XMLhttp.ReadyState & "<br>"
  Response.Write "<b>StatusText (Value must be OK): </b>" & XMLhttp.StatusText & "<br>"
  Response.Write "<b>AllResponseHeaders:</b><br>" & XMLhttp.GetAllResponseHeaders & "<br>"
  '-----------------------------------------------------------------------
  ' Get XML response from AT&T Extranet
  '-----------------------------------------------------------------------
  Set xmlDoc2 = CreateObject("MSXML2.DOMDocument")
  xmlDoc2.setProperty "ServerHTTPRequest", True
  xmlDoc2.async = False
  xmlDoc2.LoadXML XMLhttp.ResponseXML.xml
  Response.Write "<br>"
 
  Response_Doc = xmlhttp.responseXML.xml
  Response.Write "<textarea rows=20 cols=100  id=textarea1 name=textarea1>" & Response_Doc  & "</textarea>"
 
  Response.Write "<br><br><br><b>ATT Profile Results</b><br>"
  Response.Write "-----------------------------------------<br>"
 
  '-----------------------------------------------------------------------
  ' Parse the XML response from Intercall Extranet and retrieve the URL
  '-----------------------------------------------------------------------
 
  Set objDOM = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
  objDOM.loadXML Response_Doc
  Set objNode = objDOM.documentElement.selectSingleNode("Response/PunchOutSetupResponse/StartPage/URL")
  If Not ObjNode Is Nothing Then
      strURL = objNode.text
      Response.Write "<br>The URL  " & strURL & "<br>"
      Response.Redirect strURL
  End If
 
End if  
SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, I just noticed something else (I cut-and-pasted your code) The progid is incorrect.  Use:

Set xmlObj = CreateObject("Msxml2.FreethreadedDomDocument")
xmlObj.SetProperty "ServerHTTPRequest", True
xmlObj.async = False
xmlObj.load  StrURL


And if you get this error:

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'MSXML4.ServerXMLHTTP'

Then the progid is incorrect here too.  It should be "MSXML2.ServerXMLHTTP"

Regards,
Mike Sharp
You have the progid incorrect in a number of places, actually!  ;^)

  Set objDOM = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")

should be:

  Set objDOM = Server.CreateObject("Msxml2.FreethreadedDomDocument")

For a bit of clarification, this:  "Microsoft.FreeThreadedXMLDOM"  identifies the old MSXML 2 parser.  MSXML 3, SP1 or later, installs in replace mode, and re-maps the progid to the newer parser, so it will actually work with the old ProgID.  But it's still wrong, and could conceivably cause problems.  Don't use any progid that starts with "Microsoft" as this refers to the old parser.


Regards,
Mike Sharp
Avatar of CIT_DEV
CIT_DEV

ASKER

When i changed to the following line of code.

StrURL        = "http://att.ws.com/UserXML.asp"

Set xmlObj = CreateObject("Msxml2.FreethreadedDomDocument")
xmlObj.SetProperty "ServerHTTPRequest", true
xmlObj.async = False
xmlObj.load  StrURL
.....etc


I GET THE FOLLOWING ERROR

Error Code: -1072896681
Error Code: -1072896681
Error Description: Invalid xml declaration.
Error File Position: 4
Error Line: 2
Error Line Position: 3
Error URL pointing the loaded document http://att.ws.com/UserXML.asp
Error Source Text:

And WHEN I OPEN THE http://att.ws.com/UserXML.asp in the browser, i get a fully quality XML file stream.
I'm pretty sure this is a parse error though.  I wonder if the XML produces a byte order mark (hence the error message saying file position 4) that's incorrect.  Using IE to load the XML is probably a lot more forgiving regarding character encoding and the BOM.

Can you expose the source XML to the internet for me to look at?

Regards,
Mike Sharp
Also, be sure there is no whitespace *before* the XML Declaration in the XML.  If you have a newline before the declaration, the XML will open in IE, but it will throw a parse error if you try to use the documentObject.load() method.

Regards,
Mike Sharp
Avatar of CIT_DEV

ASKER

Here goes the XML file.

<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="8/12/2004 4:03:18 P93766443@attws.com" xml:lang="en-US" timestamp="1999-03-12T18:39:09-08:00">
      <Header>
            <From>
                  <Credential domain="AribaNetworkUserId">
                        <Identity>DI001</Identity>
                  </Credential>
            </From>
            <To>
                  <Credential domain="DUNS">
                        <Identity>176899-T</Identity>
                  </Credential>
            </To>
            <Sender>
                  <Credential domain="AribaNetworkUserId">
                        <Identity>0001</Identity>
                        <SharedSecret>BJ1^msnD</SharedSecret>
                  </Credential>
                  <UserAgent>Ariba ORMS 5.1P4 </UserAgent>
            </Sender>
      </Header>
      <Request>
            <PunchOutSetupRequest operation="create">
                  <BuyerCookie>34234234ADFSDF234234</BuyerCookie>
                  <Extrinsic name="TSANumber"/>
                  <Extrinsic name="RequestorFirstname">Smith</Extrinsic>
                  <Extrinsic name="RequestorMiddlename">Praker</Extrinsic>
                  <Extrinsic name="RequestorLastname">Swensons</Extrinsic>
                  <Extrinsic name="Email">ces5@attws.com</Extrinsic>
                  <Extrinsic name="RequestorLocation">M.20.2B</Extrinsic>
                  <Extrinsic name="RequestorEmployeeID">00725679G</Extrinsic>
                  <Extrinsic name="Firstname">Smith</Extrinsic>
                  <Extrinsic name="Middlename">Praker</Extrinsic>
                  <Extrinsic name="Lastname">Swensons</Extrinsic>
                  <Extrinsic name="ClientEmail">ces78715@attws.com</Extrinsic>
                  <Extrinsic name="Location">M.20.2B</Extrinsic>
                  <Extrinsic name="EmployeeID">007679G</Extrinsic>
                  <BrowserFormPost>
                        <URL>https://att.ws.com/ReadXML.asp</URL>
                  </BrowserFormPost>
                  <ShipTo>
                        <Address>
                              <Name xml:lang="en"/>
                              <PostalAddress>
                                    <DeliverTo>Smith Swensons</DeliverTo>
                              </PostalAddress>
                        </Address>
                  </ShipTo>
            </PunchOutSetupRequest>
      </Request>
</cXML>
Avatar of CIT_DEV

ASKER

There is no white space before the XML file.
Actually, I was hoping to access it over HTTP, so I could look at headers and things.  It almost has to be either a BOM is present, or there is some character before the <?xml in the declaration.

Can you look at the parseError object?  what message does it produce?

set myErr = xmlDoc.parseError
If myErr.errorCode <> 0 Then
   Response.Write myErr.reason
Else

Regards,
Mike Sharp
Avatar of CIT_DEV

ASKER

Hi Mike

Hre is the errors i get.

No data is available for the requested resource. Error Code: -2146697209

Error Code (ParseError): -2146697209
Error Description(ParseError.reason): No data is available for the requested resource.
Error File Position(ParseError.filepos): 0
Error Line(ParseError.line): 0
Error Line Position(ParseError.linepos): 0

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CIT_DEV

ASKER

Mike That description as very informative. You deserve more than 500 point for the explaination you have provided. Points on the way..


I knocked most of the issues but i am having issues with my parsing an XML document.

I beileve it has sometime to do with our servers. It woks fine on server without any fiewall restriction but fails on the other server which has restictions.

On careful analysis i found that the error was because the DTD could not be validated. I get tge following error.

Error processing resource 'http://xml.cXML.org/schemas/cXML/1.2.008/cXML.dtd'.
Can we disable the DTD Validation while loading an xml file.

The following is the line of codes..

||||||||||||||||||||||||||||||||||||||||
Response_Doc holds the XML file content . I have included a copy of the xml file.

||||||||||||||||||||||||||||||||||||||||

      Set objDOM = Server.CreateObject("MSXML.DOMDOCUMENT")
      objDOM.loadxml Response_Doc
      Response.Write "<b>Error Description(xmlObj.ParseError.reason ):</b> " & xmlObj.ParseError.reason & "<br>"

      Set objNode = objDOM.documentElement.selectSingleNode("Response/PunchOutSetupResponse/StartPage/URL")
      If Not ObjNode Is Nothing Then
            strURL = objNode.text
            Response.Write "<br>The URL  " & strURL & "<br>"
      End If


||||||||||||||||||||||||||||||||||||||||
XML FILE THAT NEEDS TO BE PARSED
||||||||||||||||||||||||||||||||||||||||

<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.008/cXML.dtd">
<cXML payloadID="OWNV1GD3ZJMPLB4R0EZSFFA-1092949249658" timestamp="2004-08-19T14:00:49PDT" xml:lang="en-US"><Response><Status code="200" text="OK"/><PunchOutSetupResponse><StartPage><URL><![CDATA[https://business.attwireless.com/platform/cXML/PunchOutStartupDispatch;dsessionid=OWNV1GD3ZJ4R0EZSFFA?&operation=create]]></URL></StartPage></PunchOutSetupResponse></Response></cXML>


Avatar of CIT_DEV

ASKER

Mike.

I checked the MSDN and found the answer. I would like to share with others on this community.

By using properites ValidateOnparse and resolveexternals i fixed my code.

objDOM.validateOnParse = false
objDOM.resolveExternals = false
In fact, I routinely set those properties whether I need to or not.  In fact, I also routinely set the SelectionLanguage secondary property as well, because I might end up using an XPath expression that isn't backwards compatible with the old MSXML 2 parser, and I hate surprises.... (jscript):

objDOM.setProperty("SelectionLanguage", "XPath");

Regards,
Mike Sharp