XML Data Feeds - Some Questions

Hi All,

Is there anything special I need to know about providing xml data feeds
with rails as far as user agents, or browser specific information is
concerned? Will one data feed differ from another in any way?

Are there any gotchas or watchout issues with XML that I might encounter
along the way?

I’m hoping to be processing some XML data feeds directly to college
football stadiums soon and I’m building a plugin for CrossFire
Hardware/Software compatibility.

Thanks in advance.

Alpha B. wrote:

I’m hoping to be processing some XML data feeds directly to college
football stadiums soon and I’m building a plugin for CrossFire
Hardware/Software compatibility.

I assume you’re referring to RSS or ATOM when you say “XML data feeds?”
Making this assumption, most feed readers I know of can handle both RSS
and ATOM. You just need to make sure you’re providing the feed in the
proper format for the readers that will be used to consume your feeds.

Is there anything special I need to know about providing xml data feeds
with rails as far as user agents, or browser specific information is
concerned? Will one data feed differ from another in any way?

Also there is a way in some browsers (at least Safari) where you can
place a meta tag in the head section that will display the RSS button
in the address bar. At least that’s how I think that feature works.

Here is an example form the Apple start page:

Hi Robert,

One of the companies I’m trying to work with just requires xml data that
they use for plugins to their video system. So, when I say xml feeds
I’m simply implying feeding xml data to their system.

I know I could simply just perform a standard xml render and have them
pull and parse off of that. However, I may want to organize that so it
reads better.

Let me provide you a brief example of an xml fed document that I might
have:

http://pastie.org/593376

As it stands now the generic xml data is placed into a teams container
with two sub containers for team. I may want to change this so that it
looks like such:

... ... ... ... etc. ... ... ... ... etc.

I’m just trying to come up with a proper way of rendering the xml in
such a fashion that whatever plugin they use can find and sort the data
properly. So, I’m weighing my options on how to render the xml.

From my limited understanding with xml in rails, an xml builder is
something that is used for say tables/grids? I don’t think I need
formatting like that. I just need an xml file that they can use to pull
data from.

Any tips would be appreciated.

Many thanks.

Hi all,

Okay I figured it out myself.

In the controller, I changed the following:

respond_to do |format|
format.html
format.js
format.xml { render :xml => @virtuals }
end

TO

respond_to do |format|
format.html
format.js
format.xml
end

… and then created an index.xml.builder file

In the builder file, I did something similar:

xml.instruct!
xml.virtuals do
@virtuals.each do |virtual|
xml.virtual do
xml.tsrs virtual.tsrs
etc…
end
end
end

This allows you to remove the pre-rendered xml and replace it with your
own tags.

Alpha B. wrote:

This allows you to remove the pre-rendered xml and replace it with your
own tags.

Yes, I thought that might be the case. I know that many people actually
do use ATOM for this purpose rather than a custom XML format. Using a
known representation like ATOM can sometime make the parsing of the data
on the client-side easier by taking advantage of existing parsers. For
example: using an RSS or ATOM feed a client could use any RSS feed
reader to monitor the data feed. That may or may not be useful in your
case.

But, in either case what you showed is how one would use the XML builder
templates. It just depends on wether you want to feed that data as
PO-XML, RSS, or ATOM.

Hi Robert,

So, I’ve finished version 1 of the xml piece for my virtual match-ups
page. It looks like so:

http://gist.github.com/174270

I’ll look into the other areas you recommended.

Hi Robert,

I’m not sure what the client will want created to be honest. So, at
this point, I’m simply trying to get the data to appear how it should if
someone were to view an xml file.

I also just figured out how to add custom tag groupings:

xml.instruct!
xml.virtuals do
@virtuals.each do |virtual|
xml.virtual do
xml.team virtual.formal_name
xml.tsrs virtual.tsrs
xml.offense{
xml.total_offense virtual.to_ydspgm
}
end
end
end

In the case above, I want to wrap an offense element around offensive
stats so I’m doing it this way. It’s looking good so far. Once I get
this done, I’ll have to find out what the client wants.

What do you suggest based on what you see me doing currently?

Alpha B. wrote:

Hi Robert,

So, I’ve finished version 1 of the xml piece for my virtual match-ups
page. It looks like so:

http://gist.github.com/174270

I’ll look into the other areas you recommended.

I like it! Very clean and easy to understand and parse. The only
suggestion I might have would be to included a little meta-information
indicating the data type for some of the fields:

Example:

Alabama
81.6628

This is not at all vital, but can sometimes be a useful convenience to
the consumers of your document.

Thanks for the feedback Robert. I’m implementing that now for the
numbers.

In case someone else follows this thread, the way to implement type with
xml.builder is by doing the following:

You convert the old syntax:

xml.total_offense team.to_ydspgm

TO the new syntax

xml.total_offense(team.to_ydspgm, :type => “float”)

I hope that helps.

I updated what the xml data looks like now:

http://gist.github.com/174270

Alpha B. wrote:

I updated what the xml data looks like now:

http://gist.github.com/174270

Cool. Now it’s clear to the consumer what to expect, rather than having
to treat everything as a string.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs