ellandrd
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</p assword><a ction>add< /action><c ontact><pr efix></pre fix><first name>'+fir stname+'</ firstname> <lastname> '+lastname +'</lastna me><addres s1></addre ss1><addre ss2></addr ess2><city ></city><c ounty></co unty><post code></pos tcode><cou ntry>Unite d Kingdom</country><email>'+ email+'</e mail><work phone></wo rkphone><h omephone>' +tel+'</ho mephone><m obilephone >'+mobile+ '</mobilep hone><dg_m edia>0</dg _media><ad m_email_st atus>norma l</adm_ema il_status> <adm_post_ status>nor mal</adm_p ost_status ><adm_sms_ status>nor mal</adm_s ms_status> <cr1></cr1 ><cr2></cr 2><cr3></c r3><cr4></ cr4><cr6>< /cr6><cr7> </cr7><cr8 ></cr8><cr 9></cr9><c r10></cr10 ><cr11></c r11><cr12> </cr12><cr 13></cr13> <cr14></cr 14><intera ction><int eractionti tle>Genera l Contact Form</interactiontitle><in teractiond esc>'+mess age+'</int eractionde sc></inter action></c ontact></r equest>';
//console.log(xmlString);
$.ajax(
{
cache:false,
processData:false,
type:"POST",
url:"http://domain.com/api/add.asp",
data:xmlString,
success:function(data,text Status,XML HttpReques t){},
error:function(XMLHttpRequ est,textSt atus,error Thrown){al ert(XMLHtt pRequest + "\n\n" + textStatus + "\n\n" + errorThrown);},
complete:function(XMLHttpR equest,tex tStatus){}
});
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</p assword><a ction>add< /action><c ontact><pr efix></pre fix><first name>test< /firstname ><lastname >user</las tname><add ress1></ad dress1><ad dress2></a ddress2><c ity></city ><county>< /county><p ostcode></ postcode>< country>Un ited Kingdom</country><email>em ail@domain .com</emai l><workpho ne></workp hone><home phone>0</h omephone>< mobilephon e>0</mobil ephone><dg _media>0</ dg_media>< adm_email_ status>nor mal</adm_e mail_statu s><adm_pos t_status>n ormal</adm _post_stat us><adm_sm s_status>n ormal</adm _sms_statu s><cr1></c r1><cr2></ cr2><cr3>< /cr3><cr4> </cr4><cr6 ></cr6><cr 7></cr7><c r8></cr8>< cr9></cr9> <cr10></cr 10><cr11>< /cr11><cr1 2></cr12>< cr13></cr1 3><cr14></ cr14><inte raction><i nteraction title>Gene ral Contact Form</interactiontitle><in teractiond esc>Test%2 0Message%2 05</intera ctiondesc> </interact ion></cont act></requ est>;
I've never seen this before and a little confused. I believe this is whats causing my CRM API request to fail.
Please advise?
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</p
//console.log(xmlString);
$.ajax(
{
cache:false,
processData:false,
type:"POST",
url:"http://domain.com/api/add.asp",
data:xmlString,
success:function(data,text
error:function(XMLHttpRequ
complete:function(XMLHttpR
});
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</p
I've never seen this before and a little confused. I believe this is whats causing my CRM API request to fail.
Please advise?
Is the semicolon a part of the posted data?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solution no longer required but thanks for time and advise