Jump to:

23023 Posts in 11882 Topics by 2830 members

General Questions

SilverStripe Forums » General Questions » self-closing tags error using xml template in IE

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

Page: 1
Go to End
Author Topic: 1584 Views
  • schellmax
    Avatar
    Community Member
    126 Posts

    self-closing tags error using xml template in IE Link to this post

    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).

  • b0bro
    Avatar
    Community Member
    38 Posts

    Re: self-closing tags error using xml template in IE Link to this post

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

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: self-closing tags error using xml template in IE Link to this post

    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.

  • socks
    Avatar
    Community Member
    190 Posts

    Re: self-closing tags error using xml template in IE Link to this post

    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.

    1584 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.