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

Reading xml file from static resource "Content is not allowed in prolog"

I tried this out to get translated texts to my Visualforce PDF.


I have for example en_US.xml file in my static resource zip file that I try to read. However I got error: 



ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.
An unexpected error has occurred. Your development organization has been notified.


I create new PageReference to the xml file, then throw that content to my xml parser.


This is my test method that fails with that error:


static testMethod void testXml(){ // test with content blob // Get the content blob from the localization file PageReference pr = new PageReference('/resource/1235260888000/Budget__pdfresources/en_US.xml'); Blob conBlob = pr.getContent(); ContentXmlParser c2 = new ContentXmlParser(); String str2 = conBlob.toString(); TempCover[] tmpc2 = c2.parseCovers(str2); system.debug(tmpc2); System.assert(tmpc2.size() == 1); System.assertEquals('Dear customer,', tmpc2[0].salutation); System.assert(tmpc2[0].body == 'Thank you for your invitation to offer for the project. Based on the information ... '); }


 Any idea what's wrong or am i trying the impossible ?


Ron HessRon Hess
I think Custom Labels are the way to get translated strings into Visualforce, have you looked into this new feature?

I don't know if this will solve your problem but that is not an appropriate way to access a static resource.  You should never be reverse engineering the URL for a static resource (notice the timestamp in the url).


If I were you I would actually query for the static resource by name and then read in staticresource.body to a Blob. 


Thanks Jill and Ron,


Custom Labels are great but do not help me because I'd need Locale dependency - i.e. Canadiens French and Belgians French - that's why my custom xml's :smileysad:



Jill I didn't know that you can actually query S.R.'s, so I will change that, I suppose file cannot be inside zip for this to work though.


...and after some investigation found that my error is due to BOM in my file, it works now ok.





I know this post is ancient but just replying in case people use it for reference. Ron is talking about Translation Workbench with works together with cusom label to create locale and language specific translations.