# Parsing XML file with no style info with Hpricot

**URL:** <https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725>\
**Category:** Rails\
**Created:** [March 7, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725 "2010-03-07T13:10:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/1 "2010-03-07T13:10:42Z")

</div>

Hello,

I’ve been trying for hours to parse an XML using Hpricot. Usually it’s  
not a problem. Here’s my simple code:

#This works and outputs the proper xml data  
@url1 = ‘[http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml](http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml)’  
@page1 = Hpricot(open(@url1))  
\<%= @page 1 %\>

#This does not work, and I’m scratching my head  
@url1 =  
‘[http://gd2.mlb.com/components/game/mlb/year\_2010/month\_03/day\_06/gid\_2010\_03\_06\_anamlb\_oakmlb\_1/boxscore.xml](http://gd2.mlb.com/components/game/mlb/year_2010/month_03/day_06/gid_2010_03_06_anamlb_oakmlb_1/boxscore.xml)’  
@page1 = Hpricot(open(@url1))  
\<%= @page 1 %\>

The [gd2.mlb.com](http://gd2.mlb.com) XML file does not have any style information according  
to Firefox. I can read it using Oxygen. Can somebody provide me with a  
hint on how to parse the [mlb.com](http://mlb.com) XML? Thanks!

-A

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 6:24pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/2 "2010-03-07T18:24:02Z")

</div>

Any idea how to parse this XML?

-A

Allan L. wrote:

> Hello,
> 
> I’ve been trying for hours to parse an XML using Hpricot. Usually it’s  
> not a problem. Here’s my simple code:
> 
> #This works and outputs the proper xml data  
> @url1 = ‘[http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml](http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml)’  
> @page1 = Hpricot(open(@url1))  
> \<%= @page 1 %\>
> 
> #This does not work, and I’m scratching my head  
> @url1 =  
> ‘[http://gd2.mlb.com/components/game/mlb/year\_2010/month\_03/day\_06/gid\_2010\_03\_06\_anamlb\_oakmlb\_1/boxscore.xml](http://gd2.mlb.com/components/game/mlb/year_2010/month_03/day_06/gid_2010_03_06_anamlb_oakmlb_1/boxscore.xml)’  
> @page1 = Hpricot(open(@url1))  
> \<%= @page 1 %\>
> 
> The [gd2.mlb.com](http://gd2.mlb.com) XML file does not have any style information according  
> to Firefox. I can read it using Oxygen. Can somebody provide me with a  
> hint on how to parse the [mlb.com](http://mlb.com) XML? Thanks!
> 
> -A

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/3 "2010-03-07T18:36:23Z")

</div>

On Sun, Mar 7, 2010 at 4:10 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> #This does not work, and I’m scratching my head

And I’m scratching mine trying to guess what you mean by “does not  
work” …

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 6:39pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/4 "2010-03-07T18:39:32Z")

</div>

Hpricot is not parsing the MLB xml file. I’m thinking the reason that it  
is not reading the MLB xml file is because it is not in a standard XML  
format.

If you give my code a quick try, you’ll notice that it will read other  
XML files, but not the MLB XML.

#This works and outputs the proper xml data  
@url1 = ‘[http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml](http://www.sportingnews.com/stories/sportingnews/MLB/rss.xml)’  
@page1 = Hpricot(open(@url1))  
\<%= @page1 %\>

#This does not work, and I’m scratching my head  
@url1 =  
‘[http://gd2.mlb.com/components/game/mlb/year\_2010/month\_03/day\_06/gid\_2010\_03\_06\_anamlb\_oakmlb\_1/boxscore.xml](http://gd2.mlb.com/components/game/mlb/year_2010/month_03/day_06/gid_2010_03_06_anamlb_oakmlb_1/boxscore.xml)’  
@page1 = Hpricot(open(@url1))  
\<%= @page1 %\>

Hassan S. wrote:

> On Sun, Mar 7, 2010 at 4:10 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > #This does not work, and I’m scratching my head
> 
> And I’m scratching mine trying to guess what you mean by “does not  
> work” …
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 6:44pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/5 "2010-03-07T18:44:35Z")

</div>

On Sun, Mar 7, 2010 at 9:39 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you give my code a quick try, you’ll notice that it will read other  
> XML files, but not the MLB XML.

Actually, I already did, and it seems to work just fine. Hence my own  
head-scratching. 🙂

So, again, maybe you can say _exactly_ what you expect to happen  
and how that differs from what you’re seeing.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 8:57pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/6 "2010-03-07T20:57:29Z")

</div>

On Mar 7, 6:18 pm, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m expecting the XML information seen here on Firefox:[http://picasaweb.google.com/lh/photo/X7VFocR3L4S4Pl\_2jvDzVQ?feat=dire](http://picasaweb.google.com/lh/photo/X7VFocR3L4S4Pl_2jvDzVQ?feat=dire)…
> 
> to be displayed when I parse the MLB file. Hpricot is not parsing this  
> file.

Have you tried viewing the source of the page generated by your view?  
I suspect hpricot is parsing the file but just blatting it into the  
view like that is producing invalid html which your browser is not  
rendering.

Fred

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 7:18pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/7 "2010-03-07T19:18:55Z")

</div>

Hi Hassan,

This picture:  
[http://picasaweb.google.com/lh/photo/Qf4DFta9p5ERoCRb6Lbd2Q?feat=directlink](http://picasaweb.google.com/lh/photo/Qf4DFta9p5ERoCRb6Lbd2Q?feat=directlink)

This is the parsed output from the feed from the sportingnews XML file.  
It  
is displayed on my view with \<%= @page1 %\>.

This picture:  
[http://picasaweb.google.com/lh/photo/xLVr8\_U-x12rJnADs\_qcEw?feat=directlink](http://picasaweb.google.com/lh/photo/xLVr8_U-x12rJnADs_qcEw?feat=directlink)

The blank space what is displayed on the view with \<%= @page1 %\> using  
the MLB XML file.

I’m expecting the XML information seen here on Firefox:  
[http://picasaweb.google.com/lh/photo/X7VFocR3L4S4Pl\_2jvDzVQ?feat=directlink](http://picasaweb.google.com/lh/photo/X7VFocR3L4S4Pl_2jvDzVQ?feat=directlink)

to be displayed when I parse the MLB file. Hpricot is not parsing this  
file.

-A

Hassan S. wrote:

> On Sun, Mar 7, 2010 at 9:39 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > If you give my code a quick try, you’ll notice that it will read other  
> > XML files, but not the MLB XML.
> 
> Actually, I already did, and it seems to work just fine. Hence my own  
> head-scratching. 🙂
> 
> So, again, maybe you can say _exactly_ what you expect to happen  
> and how that differs from what you’re seeing.
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 8, 2010, 11:13am UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/8 "2010-03-08T11:13:15Z")

</div>

Thanks everybody. I saw the info on the source. I figured it out.

-A

Hassan S. wrote:

> On Sun, Mar 7, 2010 at 10:18 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > I’m expecting the XML information seen here on Firefox:  
> > /  
> > to be displayed when I parse the MLB file. Hpricot is not parsing this  
> > file.
> 
> Sure it is – use irb to examine what’s in @page1.
> 
> As Frederick already suggested, you apparently have a view problem,  
> not an Hpricot parsing problem.
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

---

<div class="post-metadata">

**Author:** ![allanium](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@allanium](https://www.ruby-forum.com/u/allanium)\
**Post date:** [March 7, 2010, 9:56pm UTC](https://www.ruby-forum.com/t/parsing-xml-file-with-no-style-info-with-hpricot/184725/9 "2010-03-07T21:56:02Z")

</div>

On Sun, Mar 7, 2010 at 10:18 AM, Allan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m expecting the XML information seen here on Firefox:  
> /  
> to be displayed when I parse the MLB file. Hpricot is not parsing this  
> file.

Sure it is – use irb to examine what’s in @page1.

As Frederick already suggested, you apparently have a view problem,  
not an Hpricot parsing problem.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
