Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

sending XML string to an API returns an XML error of XML not well formed. Missing root element

I'm sending a well formed validate XML string to an CRM's API.  I use jQuery 1.4.3 and a $.ajax() call.  However the API failed to load the XML string as it says the XML is not well formed.  the API support team tell me the XML string has no root element based on their error logs.  

My XML string has a root element so some confusion here...

I use Safari and after checking the header returned when the API fails I noticed the root element is incorrect even though I'm sending it correct.

For example:

var xmlString = '<?xml version="1.0" ?><request><password>xx</password><action>add</action><contact><prefix></prefix><firstname>'+firstname+'</firstname><lastname>'+lastname+'</lastname><address1></address1><address2></address2><city></city><county></county><postcode></postcode><country>United Kingdom</country><email>'+email+'</email><workphone></workphone><homephone>'+tel+'</homephone><mobilephone>'+mobile+'</mobilephone><dg_media>0</dg_media><adm_email_status>normal</adm_email_status><adm_post_status>normal</adm_post_status><adm_sms_status>normal</adm_sms_status><cr1></cr1><cr2></cr2><cr3></cr3><cr4></cr4><cr6></cr6><cr7></cr7><cr8></cr8><cr9></cr9><cr10></cr10><cr11></cr11><cr12></cr12><cr13></cr13><cr14></cr14><interaction><interactiontitle>General Contact Form</interactiontitle><interactiondesc>'+message+'</interactiondesc></interaction></contact></request>';
                          
                          //console.log(xmlString);
                   
                              $.ajax(
                            {
                                cache:false,
                processData:false,
                type:"POST",
                url:"http://domain.com/api/add.asp",
                data:xmlString,
                success:function(data,textStatus,XMLHttpRequest){},
                    error:function(XMLHttpRequest,textStatus,errorThrown){alert(XMLHttpRequest + "\n\n" + textStatus + "\n\n" + errorThrown);},
                    complete:function(XMLHttpRequest,textStatus){}
});


The incorrect form data POSTed...  Not sure what this is happening - notice the <?xml version:"1.0" ?> instead of <?xml version="1.0" ?>

<?xml version:"1.0" ?><request><password>xx</password><action>add</action><contact><prefix></prefix><firstname>test</firstname><lastname>user</lastname><address1></address1><address2></address2><city></city><county></county><postcode></postcode><country>United Kingdom</country><email>email@domain.com</email><workphone></workphone><homephone>0</homephone><mobilephone>0</mobilephone><dg_media>0</dg_media><adm_email_status>normal</adm_email_status><adm_post_status>normal</adm_post_status><adm_sms_status>normal</adm_sms_status><cr1></cr1><cr2></cr2><cr3></cr3><cr4></cr4><cr6></cr6><cr7></cr7><cr8></cr8><cr9></cr9><cr10></cr10><cr11></cr11><cr12></cr12><cr13></cr13><cr14></cr14><interaction><interactiontitle>General Contact Form</interactiontitle><interactiondesc>Test%20Message%205</interactiondesc></interaction></contact></request>;

I've never seen this before and a little confused.  I believe this is whats causing my CRM API request to fail.

Please advise?  
Avatar of Shalom Carmel
Shalom Carmel
Flag of Israel image

Is the semicolon a part of the posted data?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
Avatar of ellandrd

ASKER

Solution no longer required but thanks for time and advise