!!! xml not producing <?xml version = "1.0" encoding = "UTF-8"?>

1,739 views
Skip to first unread message

DAZ

unread,
Aug 26, 2010, 11:02:12 AM8/26/10
to Haml
I'm using the following code to generate an rss feed:

!!! xml
%feed(xmlns="http://www.w3.org/2005/Atom")
%title= settings.title
%id= settings.url
%updated= @posts.first[:created_at] if @posts.any?
%author
%name= settings.author


But the output is this:
<feed xmlns='http://www.w3.org/2005/Atom'></feed>
<title>Bloggl</title>
<id>http://bloggl.com</id>
<updated>2010-08-26T15:37:35+01:00</updated>
<author>
<name>DAZ</name>
</author>

The !!! xml line doesn't seem to be producing
<?xml version = "1.0" encoding = "UTF-8"?>

Anybody know what's going wrong here?

cheers,

DAZ

Nathan Weizenbaum

unread,
Aug 26, 2010, 2:07:33 PM8/26/10
to ha...@googlegroups.com
You're probably using Rails 3, in which case Haml defaults to HTML5 format, in which XML headers don't show up. You need to set :format => :xhtml for this to work.


--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.


DAZ

unread,
Aug 27, 2010, 9:54:23 AM8/27/10
to Haml
Thanks Nathan,
I'm using Sinatra 1.0. I tried using :format => :xhtml and still the
same problem! Not sure what's going on...

DAZ
> > haml+uns...@googlegroups.com <haml%2Bunsu...@googlegroups.com>.

Peter

unread,
Aug 27, 2010, 2:36:49 PM8/27/10
to Haml
Hi DAZ and Nathan,

I have exactly the same problem in a Rails 3 RC 2 application. Started
an application from scratch with only the HAML gem, ran a 'bundle
install' and added an haml.rb file in the config/initializers file
which sets the default to :xhtml, here it is:

--------- config/initializers/haml.rb
Haml::Template.options[:format] = :xhtml
---------

Next I have the following in my application.html.haml:

--------- app/views/layouts/application.html.haml
!!! XML
%p This file should have an XML declaration but doesn't.
----------

When I remove the XML or replace it with 5, Mobile or any other tag it
works fine but the XML is ignored. Am I missing something?

Thanks!

Peter

unread,
Aug 27, 2010, 2:54:08 PM8/27/10
to Haml
I tried to add the XML declaration manually with:

DOESN'T WORK
--------- app/views/layouts/application.html.haml
<?xml version="1.0" encoding="utf-8"?>
---------

But this doesn't show anything. Adding a *space* before the question
mark does show the tag. Is there some regex stuff going on here that
rejects tags that start with a question mark?

WORKS, MIND THE SPACE
--------- app/views/layouts/application.html.haml
< ?xml version="1.0" encoding="utf-8"?>
---------

Hope this helps pointing in the right direction.

Nathan Weizenbaum

unread,
Aug 27, 2010, 4:55:20 PM8/27/10
to ha...@googlegroups.com
Something strange is going on here. Haml should pass all lines beginning with "<" straight through to source. I'll check it out some time this weekend.

To unsubscribe from this group, send email to haml+uns...@googlegroups.com.

Peter

unread,
Aug 27, 2010, 7:26:38 PM8/27/10
to Haml
DAZ, are you using Google Chrome for your development?
Nathan, I think I found the problem and it has nothing to do with
HAML, I'm sorry to bother you with this.

If you right click "View Page Source" in Google Chrome it shows the
source of the document but *HIDES* the XML declaration. I opened the
same file in Firefox, right click "View Page Source" and tadaa, there
it is. Checked Safari and sure, it's there.

So conclusion: for some strange reason Google Chrome doesn't think
it's important to show the XML declaration in the source view. If you
use Webkit's resource inspector (View > Developer > Developer Tools)
and look at the source that way you'll see it's there.

So DAZ, can you confirm you are having this problem in Google Chrome
as well and not in another browser so that we can be sure we are
talking about the same problem here?

And Nathan... sorry, should have double checked before complaining.

Good night!
> > haml%2Bunsu...@googlegroups.com<haml%252Buns...@googlegroups.com>

DAZ

unread,
Aug 28, 2010, 2:51:36 AM8/28/10
to Haml
Yes I'm using Chromium browser on Ubuntu! Thanks for spotting this
Peter and sorry for bothering you Nathan.

I should have thought Chrome was to blame as I've also had problems
with it displaying 404 pages - not a great browser for development!

cheers,

DAZ
Reply all
Reply to author
Forward
0 new messages