Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

self-closing tags error using xml template in IE


Reply


4 Posts   1722 Views

Avatar
schellmax

Community Member, 126 Posts

5 May 2009 at 8:50pm

could anyone confirm the following bug before i create a ticket for it:

self-closing tags in an xml template will seem to be rewritten to regular tags, ending up in invalid markup. strangely enough, only reproducable in internet explorer. example code:

Page_Controller

   function xmlTeasers() {
      return $this->renderWith('Hometeasers_xml');
   }


Hometeasers_xml.ss

<?xml version="1.0" encoding="UTF-8"?>
<home>
   <teaser>            
      <image src="mysite/_content/thumb_motionmeta.jpg" posx="300" posy="10" />
   </teaser>
</home>


when you render this in IE and view the source code, the slash of the self-closing tag 'image' is gone.
tried feeding the xml to flash and it threw an xml error ('image tag not closed')

i also tried 'ContenNegotiator::disable()', but doesn't seem to have any effect (2.3.1).

Avatar
b0bro

Community Member, 38 Posts

16 September 2009 at 5:37pm

Did you find a solution to this, I have the same problem and its a massive pain in the backside!!!!!

Avatar
dalesaurus

Community Member, 283 Posts

17 September 2009 at 3:00am

Have you taken a look at the Convert::raw2xml() function? SS has a pretty robust XMLDataFormatter that will handle entire DataObjects, but I think you just need to pass your data through the Convert functions before doing ->customise($data)->renderWith(). If you are rendering in your template with the .XML call it will be properly escaped in my experience.

Avatar
socks

Community Member, 190 Posts

12 October 2009 at 9:25am

Edited: 20/10/2009 1:59pm

I'm in the middle of doing a Google Map populated with locations entered into DataObjectManager...

I had the same issue, it would strip the <?xml version="1.0" encoding="UTF-8"?> and reformat <marker ..... /> to <marker ....>.

I added $this (taken from one of the google map modules):

function GMapXml() {      
   return DataObject::get('StoreLocation');
   return $this->customise('StoreLocation')->renderWith('GoogleMapXML');
   $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
}

With the addHeader, everything worked. In my case I didn't need to do anything with ContentNegotiator. Google didn't care whether it was <marker .../> or <marker ...></marker>.
EDIT: Google didn't care, but IE sure did. It didn't recognize <marker ../> as an object. I changed to <marker ...></marker> and IE stopped whining.

I think it would be more proper to use text/xml instead of application/xml, but I don't know that for sure. Also, I could never see the header change when viewing with FF plugin - Live HTTP Headers. It always said text/html.
EDIT: I read on another site that suggested that application/xml is preferred.