1

I am creating an xml from salesforce database, Everything works fine except when there is a & in the data which is been fetched.

<apex:page contenttype="text/xml" 
> controller="Test2ab" >  <data
> wiki-section="Timeline"> <apex:repeat
> value="{!lsttask}" var="e" > <event
> start="{!e.ActivityDate}" title=
> "{!e.Subject}"> <apex:outputText
> value="{!e.Subject}" /> </event>
> </apex:repeat> </data></apex:page>

and in the controller i am just querying

>  lsttask   =[Select OwnerId,WhoId,Status,Subject,ActivityDate from Task where Status = 'Completed' Order By ActivityDate Desc];

How can i use an escape for the value retrieved from the database
Thanks Prady

3 Answers 3

1

I know very little about APEX/Salesforce but as you're building an XML from strings fetched from the database you probably need to call the replace method of the string:

string.replace("&","&amp;")

http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf

you might also want top look at replacing < with &lt;, > with &gt;,' with &apos; and " with &quot;

Sign up to request clarification or add additional context in comments.

Comments

0

In your example, this works well:

<apex:outputText value="{!HTMLENCODE(e.Subject)}" escape="false" />

In simpler cases you can also use:

{!HTMLENCODE(e.Subject)}

Here is a summary of HTMLENCODE and other Salesforce functions An example of pairing apex:outputText with HTMLENCODE and escape=false is in the Apex Dev Guide

Comments

0

This might help as well. I realize it's late to the game, but it may help others that visit this topic.

http://it.toolbox.com/blogs/anything-worth-doing/a-better-way-to-generate-xml-on-salesforce-using-visualforce-55433

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.