# Get content in a xml element using hpricot

**URL:** <https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906>\
**Category:** Ruby\
**Created:** [April 13, 2007, 9:48am UTC](https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906 "2007-04-13T09:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bonita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@Bonita](https://www.ruby-forum.com/u/Bonita)\
**Post date:** [April 13, 2007, 9:48am UTC](https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906/1 "2007-04-13T09:48:45Z")

</div>

Hi

I’m using hpricot to parse the following file.

[from morwyn] \* HTML for the Conceptually Challenged http://del.icio.us/url/50666d1a3fe2b942b20819ec2919d2b7#morwyn HTML for the Conceptually Challenged. Very basic tutorial, plainly worded for people who hate to read instructions. morwyn 2006-10-10T07:28:28Z html imported webpagedesign 

I’m trying to get the content from dc:subject like this

doc = Hpricot.parse(File.read(“965.xhtml”))

(doc/“item”).each do |t|

puts (t/“dc:subject”).innerTEXT

end

but I got

dc:subjecthtml internet tutorial web\</dc:subject\>

while I only need “html internet tutorial web”

Anyone knows what’s the right function to call?

THanks

---

<div class="post-metadata">

**Author:** ![Bonita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@Bonita](https://www.ruby-forum.com/u/Bonita)\
**Post date:** [April 13, 2007, 12:45pm UTC](https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906/2 "2007-04-13T12:45:51Z")

</div>

On Apr 13, 9:48 am, Bonita [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> dc:creatormorwyn\</dc:creator\>
> 
> but I got  
> Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Bonita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@Bonita](https://www.ruby-forum.com/u/Bonita)\
**Post date:** [April 13, 2007, 12:50pm UTC](https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906/3 "2007-04-13T12:50:45Z")

</div>

Sorry for deleted your text ☹

Maybe you can try:

puts (t/“dc:subject”).text

Bonita wrote:

> I’m trying to get the content from dc:subject like this
> 
> doc = Hpricot.parse(File.read(“965.xhtml”))
> 
> (doc/“item”).each do |t|
> 
> puts (t/“dc:subject”).innerTEXT
> 
> end
> 
> but I got
> 
> dc:subjecthtml internet tutorial web\</dc:subject\>
> 
> while I only need “html internet tutorial web”
> 
> Anyone knows what’s the right function to call?
> 
> THanks

---

<div class="post-metadata">

**Author:** ![Bonita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@Bonita](https://www.ruby-forum.com/u/Bonita)\
**Post date:** [April 13, 2007, 12:50pm UTC](https://www.ruby-forum.com/t/get-content-in-a-xml-element-using-hpricot/91906/4 "2007-04-13T12:50:52Z")

</div>

On Apr 13, 12:40 pm, removed\_email\_address@domain.invalid wrote:

> > HTML for the Conceptually Challenged. Very basic tutorial,  
> > \</taxo:topics\>  
> > end
> 
> > –  
> > Posted viahttp://www.ruby-forum.com/.
> > 
> > > puts (t/‘dc:subject’).text

puts (t/‘dc:subject’).text

Sorry for the double post but I shouldn’t have copy/paste the result  
directly from irb ☹
