+ Start a Discussion

getting junk when exporting as xml



I am trying to export information from Salesforce as xml that can be used by another application locally. I wrote a controller class that will help me in parsing the xml tags and inserting the values. I then created a visualforce page that will provide the option of showing the xml string.


The controller code is

/* This is the controller class to export the required quote infomation as xml for further use in a dot net based program. */public class quotesController { /* Declaring the objects, variables and other items that will be used through out this class. */ Quote__c quotes; Quote_Line__c quoteLines; Id quoteId; List<Quote_Line__c> quoteLinesList = new List<Quote_Line__c>(); /* To make the class as the extension for the standard controller for the visualforce page calculateTax. We also get the Quote id here for which we are going to calculate the tax for. */ public quotesController(ApexPages.StandardController stdController) { this.quotes = (Quote__c)stdController.getRecord(); quotes = [select Id, Name, Quote_Name__c, Total__c from Quote__c where Id = :ApexPages.currentPage().getParameters().get('id')]; quoteId = ApexPages.currentPage().getParameters().get('id'); } /* This function is to query for the quote line items for the particular quote. Save the result of the query to the list and make the list as the return value of this function. */ public List<Quote_Line__c> getquoteLines() { quoteLinesList = [select Id, Name, Line_Item__c, Rate__c from Quote_Line__c where Quote_Number__r.Id = :quoteId]; return quoteLinesList; } /* This function is to create the xml tags and the populate them with the related values. */ public string getxmlOutput() { Integer i; String total = quotes.Total__c.format(); String rate; XmlStreamWriter xmlValues = new XmlStreamWriter(); xmlValues.writeStartDocument(null,'1.0'); xmlValues.writeProcessingInstruction('target','data'); xmlValues.writeStartElement(null,'CalculateTax',null); xmlValues.writeStartElement(null,'Quotes',null); xmlValues.writeStartElement(null,'QuoteId',null); xmlValues.writeCharacters(quotes.Id); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteNumber',null); xmlValues.writeCharacters(quotes.Name); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteName',null); xmlValues.writeCharacters(quotes.Quote_Name__c); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteTotal',null); xmlValues.writeCharacters(total); xmlValues.writeEndElement(); xmlValues.writeEndElement(); for(i = 0; i<quoteLinesList.size(); i++) { rate = quoteLinesList[i].Rate__c.format(); xmlValues.writeStartElement(null,'QuoteLines',null); xmlValues.writeStartElement(null,'QuoteLineId',null); xmlValues.writeCharacters(quoteLinesList[i].Id); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteLineNumber',null); xmlValues.writeCharacters(quoteLinesList[i].Name); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteLineName',null); xmlValues.writeCharacters(quoteLinesList[i].Line_Item__c); xmlValues.writeEndElement(); xmlValues.writeStartElement(null,'QuoteLineRate',null); xmlValues.writeCharacters(rate); xmlValues.writeEndElement(); xmlValues.writeEndElement(); } xmlValues.writeEndElement(); xmlValues.writeEndDocument(); String xmlStringOutput = xmlValues.getXmlString(); xmlValues.close(); return xmlStringOutput; }}


 The visualforce code is


<!-- The visual force page that will help to export the values from the controller extension class quotesController.--><apex:page standardController="Quote__c" extensions="quotesController" contentType="text/xml" cache="true"> <!-- contentType="text/xml-external-parsed-entity" cache="true"> --> <apex:pageBlock > <apex:repeat value="{!quoteLines}" var="qln"></apex:repeat> <apex:outputText value="{!xmlOutput}"> </apex:outputText> </apex:pageBlock></apex:page>


The first problem that i faced was that i was not able to save the output as a file. For this i used the content type text/xml-external-parsed-entity. Using this content type i was able to save it as a file.


The other problem i am not able to resolve is the fact that the output is getting wrapped inside html code. Like

f(!window.sfdcPage){window.sfdcPage = new ApexPage();} UserContext.initialize({'locale':'en_US','timeFormat':'h:mm a','today':'2\/6\/2010 12:40 AM','userPreferences':[{'value':false,'index':112,'name':'HideInlineEditSplash'} ,{'value':false,'index':114,'name':'OverrideTaskSendNotification'} ,{'value':false,'index':115,'name':'DefaultTaskSendNotification'} ,{'value':false,'index':119,'name':'HideUserLayoutStdFieldInfo'} ,{'value':false,'index':116,'name':'HideRPPWarning'} ,{'value':false,'index':87,'name':'HideInlineSchedulingSplash'}


 Please help in getting only the xml tags.



Krishnadas M R 







you probably just need escape="false" on the outputText, and get rid of the pageBlock tags.


hope that helps