# Read and parse xml

**URL:** <https://www.ruby-forum.com/t/read-and-parse-xml/174807>\
**Category:** Ruby\
**Created:** [September 2, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/read-and-parse-xml/174807 "2009-09-02T16:28:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [September 2, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/read-and-parse-xml/174807/1 "2009-09-02T16:28:12Z")

</div>

Hi all,  
I need to hit a URL that returns me a xml file,which I should read and  
parse.  
How could I do it,access the URL,retrieve the content of the response  
and process it?

Regards,  
Rafael R.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [September 2, 2009, 5:37pm UTC](https://www.ruby-forum.com/t/read-and-parse-xml/174807/2 "2009-09-02T17:37:11Z")

</div>

At 2009-09-02 10:28AM, “Rafael R.” wrote:

> Hi all,  
> I need to hit a URL that returns me a xml file,which I should read and  
> parse.  
> How could I do it,access the URL,retrieve the content of the response  
> and process it?

Read about the standard library package “open-uri” to retrieve the URL  
contents, and “Nokogiri” (gem) or “Hpricot” (gem) or “REXML” (standard  
library package) to process the XML

```
http://www.ruby-doc.org/stdlib/
http://nokogiri.rubyforge.org/nokogiri/
http://github.com/whymirror/hpricot/tree/master
```

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [September 2, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/read-and-parse-xml/174807/3 "2009-09-02T18:21:06Z")

</div>

On Sep 2, 2009, at 7:28 AM, Rafael R. wrote:

> Hi all,  
> I need to hit a URL that returns me a xml file,which I should read and  
> parse.  
> How could I do it,access the URL,retrieve the content of the response  
> and process it?

You can use open-uri for fetching the content. Then you can use  
nokogiri for processing the XML response.

Here are some docs that will get you started:

[http://nokogiri.org/](http://nokogiri.org/)

Hope that helps.

* * *

Aaron P.  
[http://tenderlovemaking.com](http://tenderlovemaking.com)
