#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    XML document must have a top level element


    Hi,

    First time I try to send XML data over HTTP from vbscript to ASP, and...it doesn't work!

    If I load an local XML file in my asp page, I can parse and display data normally.

    If I post the same xml file from my vbscript using HTTPREQUEST ASp gives me an error "XML document must have a top level element" at line 0 (but I receive the xmlhttp.responseText)
    [code]
    '---------------------------------------
    strxml = "c:\bri\note.xml"

    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    xmlhttp.open "POST", "http://server/mdlsfix/receive.asp",False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    Set xmldom = CreateObject("Microsoft.XMLDOM")

    xmlDom.load strxml
    xmlhttp.send xmldom
    MsgBox xmlhttp.responseText

    '---------------------------------------
    [code]

    When I run this reponsetext gives me the entire content of my XML (including tags)

    My asp looks like this :
    [code]
    <%
    set xmldom = Server.CreateObject("Microsoft.XMLDOM")
    xmldom.Load(Request)
    response.ContentType = "text/xml"

    If xmldom.parseError.errorCode <> 0 Then
    Set myErr = xmldom.parseError
    Response.Write myErr.reason
    Response.Write xmlDom.parseError.line
    else
    strText = "You sent me: " & xmldom.xml
    Response.Write xmldom.xml
    end if

    %>
    [code]

    Result : XML document must have a top level element. 0
    If I load the xml file directly instead of "request" I get the expected result.
    How can I get the result sent back to the client but on the server I get a parsing error.

    Could you please advise me on this. I've been browsing Internet for days trying different examples, without success.

    I also tried to use MSXML2.DOMDocument.3.0 instead, but it doesn't make any difference

    Help would be much appreciated ...

    Thanks in advance !!!

    briac
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,959
    Rep Power
    9397
    Send the XML as text, not as an XMLDOM object.

    Not that I know any VBScript (not that I know anybody who uses it, either):
    Code:
    strxml = "c:\bri\note.xml"
    
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    xmlhttp.open "POST", "http://server/mdlsfix/receive.asp",False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(strxml, ForReading)
    xmlhttp.send ts.ReadAll
    MsgBox xmlhttp.responseText

IMN logo majestic logo threadwatch logo seochat tools logo