function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
robforcerobforce 

XML CDATA using Dom.Document

I'm trying to load a Dom.Document with some XML I got from an API call. The returned XML includes nodes with CDATA. After loading the XML in the Document, the CDATA nodes are all empty. The XML is a little on the large side and using Ron Hess's XMLDom parser class hits the script statement governor limit. Does anyone have a solution for this?

dotnet developedotnet develope

Hi Friend,

 

Could you please post the error?

 

 

robforcerobforce

There isn't an error. The issue is that the new-ish Dom.Document doesn't support CDATA. To see the issue, load up an xml string with CDATA into a Dom.Document. 

 

 

<result>
<first_name>Bill</first_name>
<last_name><![CDATA[Johnson]]</last_name>
</result>

 

 

Then call toXmlString() on the Document and what you will see is all of your CDATA nodes with no data.

 

 

<result>
<first_name>Bill</first_name>
<last_name></last_name>
</result>

 

 

You can get the CDATA using the XmlStreamReader or Ron Hess's XML parser class (which uses the stream reader). The problem with that is the XML we are trying to parse is large enough that we hit the script statement governor limit even on smaller-than-production size test XML.

 

I'm not sure we have a choice other than call the web service and parse the response outside of Salesforce. I'm looking for any other suggestions.

 

Vote for this to try to get CDATA support: http://success.salesforce.com/ideaView?c=09a30000000D9xt&id=0873000000081cUAAQ&returnUrl=%2Fapex%2FideaList%3Fc%3D09a30000000D9xt