locked
XML Invalid at the top level of the document. - RetrieveMultipleRequest RRS feed

  • Question

  • Hi All,

    i am using Retrieve multiple request,

    i am able view the result in the debugg mode in req.send(requestMain)

    but i am unable to load this response from XMLHttpresponse into XMLDoc

    it is saying "Invalid at the top level of the document"

    can you all please help me.

    Thanks and Regards

    Ravi

    Thursday, September 29, 2011 8:54 AM

Answers

  • Hi

    try

            var XmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            XmlDoc.async = false;
            XmlDoc.loadXML(req.responseXML.xml);


    Mahain : MS CRM Freelancer
    • Proposed as answer by HIMBAPModerator Friday, September 30, 2011 5:51 AM
    • Marked as answer by E Ravi kumar Saturday, October 1, 2011 10:50 AM
    Thursday, September 29, 2011 10:54 AM
    Moderator
  • Hi,

    Here's what I did to access my own customized web serivce and it works:

     

    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

    xmlDoc.loadXML( xmlHttpRequest.responseXML.selectSingleNode("//YouRequestResult").text);  

    where 'YouRequestResult' is your soap response node just one level below <s:Body>

    Frank

     


    • Edited by .frank Thursday, September 29, 2011 8:48 PM
    • Proposed as answer by .frank Thursday, September 29, 2011 8:48 PM
    • Marked as answer by E Ravi kumar Friday, September 30, 2011 7:13 AM
    Thursday, September 29, 2011 8:47 PM

All replies

  • share your code here


    Mahain : MS CRM Freelancer
    Thursday, September 29, 2011 9:23 AM
    Moderator
  • Hi Mahindra i pasted my code below

    OnLoad:function()
    {
          debugger;

           var FetchMaxChannelSeqNumber =  SDK.Channels.RetriveMaximumChannelCode('<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true" ><entity name="vovinet_channel"><attribute name="vovinet_codesequencenumber" alias="sequencenumber_max" aggregate="max"/></entity></fetch>');


           debugger;  

           var MaxChannelCodeSequNumber = FetchMaxChannelSeqNumber.getElementsByTagName("sequencenumber_max");
         
           Xrm.Page.getAttribute("vovinet_codesequencenumber").setValue(MaxChannelCodeSequNumber);
         
    },

     

     

    RetriveMaximumChannelCode: function(FetchMaxChannelSeqNumberXml)
    {

            var requestMain = "";
                                 requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
                  
                                 requestMain += "<s:Body>";
                  
                                requestMain += "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
                  
                                requestMain += "<request i:type=\"a:RetrieveMultipleRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
                              
                              requestMain += " <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
                  
                              requestMain += " <a:KeyValuePairOfstringanyType>";
                 
                              requestMain += " <b:key>Query</b:key>";
                  
                              requestMain += "<b:value i:type=\"a:FetchExpression\">";

          requestMain += "<a:Query>";
                                
                              requestMain += SDK.Channels.FetchEncode(FetchMaxChannelSeqNumberXml);

                              requestMain += "</a:Query>";

                              requestMain += "</b:value>";

                              requestMain += " </a:KeyValuePairOfstringanyType>";
                            
                              requestMain += "</a:Parameters>";
                 
                              requestMain += "<a:RequestId i:nil=\"true\" />";
                  
                              requestMain += "<a:RequestName>RetrieveMultiple</a:RequestName>";
                  
                              requestMain += " </request>";
                  
                              requestMain += "</Execute>";
                  
                              requestMain += "</s:Body>";
                  
                              requestMain += "</s:Envelope>";

                 //var req = new XMLHttpRequest();
               // var req = new ActiveXObject('Msxml2.XMLHTTP');

                   var req = SDK.Channels.CreateXmlHttpObject(); // Microsot CreateXmlHttp function


                                debugger;                   

                               req.open("POST",SDK.Channels.getServerUrl(),false);

                               //req.setRequestHeader("Accept","application/xml,text/xml,*/*");                      
                        
                               req.setRequestHeader("Content-Type","text/xml; charset=utf-8");

                              //req.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
                                 req.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
              
                              debugger;

                             req.send(requestMain);
                
                               var XmlDoc = new ActiveXObject("Msxml2.DOMDocument");
                            
                              XmlDoc.async = false;
                            
                              XmlDoc.resolveExternals = false;
                            
                              XmlDoc.loadXML(req.responseXML.text);
                             
                            return XmlDoc;
    },

    in the above

    I am able to see result in req.send(requestMain)

    that is when expand "req" debug mode i am getting required result but

    the same is not loading into XmlDoc - the error coming is "Invalid at the top level of the document" 

    can you please help me Mahindra

    Thanks and Regards

    Ravi

    Thursday, September 29, 2011 9:29 AM
  • Hi Mahindra,

    did you figure it out, why it is not coming.

    Thanks and Regards

    Ravi

    Thursday, September 29, 2011 10:15 AM
  • Hi

    try

            var XmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            XmlDoc.async = false;
            XmlDoc.loadXML(req.responseXML.xml);


    Mahain : MS CRM Freelancer
    • Proposed as answer by HIMBAPModerator Friday, September 30, 2011 5:51 AM
    • Marked as answer by E Ravi kumar Saturday, October 1, 2011 10:50 AM
    Thursday, September 29, 2011 10:54 AM
    Moderator
  • Hi,

    Here's what I did to access my own customized web serivce and it works:

     

    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

    xmlDoc.loadXML( xmlHttpRequest.responseXML.selectSingleNode("//YouRequestResult").text);  

    where 'YouRequestResult' is your soap response node just one level below <s:Body>

    Frank

     


    • Edited by .frank Thursday, September 29, 2011 8:48 PM
    • Proposed as answer by .frank Thursday, September 29, 2011 8:48 PM
    • Marked as answer by E Ravi kumar Friday, September 30, 2011 7:13 AM
    Thursday, September 29, 2011 8:47 PM
  • Hi Mahindra,

    It worked, i did as mentioned above

    Thanks a lot

    Regards

    Ravi

     

    Friday, September 30, 2011 5:39 AM
  • you are welcome !!!  please close this thread.


    Mahain : MS CRM Freelancer
    Friday, September 30, 2011 5:51 AM
    Moderator
  • Hi Mahindra,

    Thanks, I closed the thread.

    Thanks and Regards

    Ravi

     

    Saturday, October 1, 2011 10:51 AM