You need to sign in to do that
Don't have an account?
Sravana Sudheer
Unable to Send data to 3rd party due to invalid XML(which contains <p>, <ul> tags)
Hi All,
Got an error saying that unable to Post the data to 3rd party service due to invalid XML in one of the Field which we are mapping from salesforce which is in HML format. Tried using CDATA tags, but seems out like it didn't resolve the issue.
Error: <Message>XML INVALID, Your XML is not valid according to Export DTD. unknown-65b0270:0: validity error : Element JobDescription was declared #PCDATA but contains non text nodes unknown-65b0270:0: validity error : No declaration for element p unknown-65b0270:0: validity error : No declaration for attribute style of element p
Tried using the below code.
JobDescription= rev.Job_Description__c; --> Job_Description__c contains html tags like <ul>, <p>,<span> etc.
String[] JD = JobDescription.split('<br>');
JobDescription='';
string JobDescriptionP='';
for(String s : JD){
JobDescription = JobDescription+'<![CDATA[<br>]]>' +s+' ';
string[] JDP=JobDescription.split('<p>');
for(string p:JDP){
JobDescriptionP = JobDescriptionP+'<![CDATA[<p>]]>'+p+' ';
system.debug('jdp-----'+JobDescriptionP);
}
JobDescription=JobDescriptionP;
system.debug('jd++++'+JobDescription);
}
Got an error saying that unable to Post the data to 3rd party service due to invalid XML in one of the Field which we are mapping from salesforce which is in HML format. Tried using CDATA tags, but seems out like it didn't resolve the issue.
Error: <Message>XML INVALID, Your XML is not valid according to Export DTD. unknown-65b0270:0: validity error : Element JobDescription was declared #PCDATA but contains non text nodes unknown-65b0270:0: validity error : No declaration for element p unknown-65b0270:0: validity error : No declaration for attribute style of element p
Tried using the below code.
JobDescription= rev.Job_Description__c; --> Job_Description__c contains html tags like <ul>, <p>,<span> etc.
String[] JD = JobDescription.split('<br>');
JobDescription='';
string JobDescriptionP='';
for(String s : JD){
JobDescription = JobDescription+'<![CDATA[<br>]]>' +s+' ';
string[] JDP=JobDescription.split('<p>');
for(string p:JDP){
JobDescriptionP = JobDescriptionP+'<![CDATA[<p>]]>'+p+' ';
system.debug('jdp-----'+JobDescriptionP);
}
JobDescription=JobDescriptionP;
system.debug('jd++++'+JobDescription);
}
[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_escapeXml
All Answers
[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_escapeXml
Thank you for your response. it works like a champ and even i tried this at the jobdescription node
<JobDescription><![CDATA['+JobDescription+']]></JobDescription>
this work in the same way like escape xml too.