nokogiri

nokogiri : how to select an element with its text content via CSS not xpath?

http://stackoverflow.com/questions/1474688/nokogiri-how-to-select-nodes-by-matching-text can do thsi via Xpath however, i am looking for a way to do a CSS select by matching the text of element. PyQuery, PHPQuery can do this. Isnt there a Jquery API lib for ruby ? ...

finding common ancestor from a group of xpath ?

say i have html/body/span/div/p/h1/i/font html/body/span/div/div/div/div/table/tr/p/h1 html/body/span/p/h1/b html/body/span/div how can i get the common ancestor? in this case span would be the common ancestor of "font, h1, b, div" would be "span" ...

get common xpath ancestor node ?

im using nokogiri. i need to get the common xpath ancestor of group of elements. ...

Getting XSLT Current Node, formatted as XPath Query?

Hi there, I have the following block of code that gets the name of the nodes down the tree, like this: section/page/subPage But I would like to be able to get it down to the following (just making it up): section[@id='someId']/page/subPage[@user='UserA']/@title I found the following code from one of these StackOverflow posts: <xsl...

Strip text from HTML document using Ruby

There are lots of examples of how to strip HTML tags from a document using Ruby, Hpricot and Nokogiri have inner_text methods that remove all HTML for you easily and quickly. What I am trying to do is the opposite, remove all the text from an HTML document, leaving just the tags and their attributes. I considered looping through the do...

Transform XML with XSLT and preserve CDATA (in Ruby)

I am trying to convert a document with content like the following into another document, leaving the CDATA exactly as it was in the first document, but I haven't figured out how to preserve the CDATA with XSLT. Initial XML: <node> <subNode> <![CDATA[ HI THERE ]]> </subNode> <subNode> <![CDATA[ SOME TEXT ]]> ...

grabbing text between all tags in Nokogiri ?

what would be the most efficient way of grabbing all texts between html tags ? <div> <a> hi </a> .... bunch of texts surrounded by html tags. ...

put each text surrounded via html tag, into an array ?

using nokogiri, doc = Nokogiri::HTML(your_html) doc.xpath("//text()").to_s this does the job, however, it puts everything into one flat text. i need to take each text surrounded via html tags <b> text</b> <h1>text3</b> and put them into array. ["text", "text3"] what is the recommended action ? i thought of doing doc.xpath("*")....

select parent node containing text inside children's node.

basically i want to select a node (div) in which it's children node's(h1,b,h3) contain specified text. <html> <div id="contents"> <p> <h1> Child text 1</h1> <b> Child text 2 </b> ... </p> <h3> Child text 3 </h3> </div> i am expecting, /html/div/ not /html/div/h1 i have this below, but unfortunately returns the children, instead of th...

Convert latin1 string to utf8?

Hello, how can I convert a string, that contains latin1 characters to utf8? The string is a document, that is opened by open-uri and that contains these special characters. Best regards ...

nokogiri: Get shortcut icon from a page

How can I do that? ...

xpath for selecting <option> html tag ?

xpath for selecting html tag ? <select> <option value="first option"> 1 </option> <option value="second option"> 2 </option> <option value="third option"> 3 </option> </select> Would below suffice ? html/body/form/select[@name='options' and @value='first option'] ...

possible to select multiple options with xpath ?

/html/body/form/select/option[@val = '1' and @val = '3'] so that means select the first and third option in a select-multiple form ? ...

how can i translate this into ruby nokogiri ?

$("br",top.document).parent().contents().each(function() { textx = this.textContent.replace(/\s+/g, '') if ( this.nodeType == 3 && textx.length ) { $(this).wrap('<div id="uniqja__' + numero + '"></div>') } }) ...

nokogiri: why is this an invalid xpath ?

//br/preceding-sibling::normalize-space(text()) i am getting invalid xpath expression with nokogiri ...

how to find all the child nodes inside the matched elements (including text nodes) ?

in jquery its quite simple for instance $("br").parent().contents().each(function() { but for nokogiri, xpath, its not working out quite well var = doc.xpath('//br/following-sibling::text()|//br/preceding-sibling::text()').map do |fruit| fruit.to_s.strip end ...

variable from controller into view in rails?

I know this might be a dumb question. I'm trying to use this xml parser http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html I've put the code below in a controller in a bringRSS method(?), and it works fine in IRB. But how do I get values for puts link.content into my views def bringRSS require 'nokogiri' require 'open-uri' ...

How to do a regex search in nokogiri

given: require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) "<html> <body> <p id='para-1'>A</p> <div class='block' id='X1'> <h1>Foo</h1> <p id='para-2'>B</p> </div> <p id='para-3'>C</p> <h2>Bar</h2> <p id='para-4'>D</p> <p id='para-5'>E</p> <div class='block' id='X2'> <p id='para-6...

Finding a text node in xml using xpath problem

I'm using rails and the Nokogiri parser. My xml is as below and I'm trying to get the 'Biology: 08:00' text into my view. <rss version="2.0"> <channel> <item> <title>Biology: 08:00</title> <description>Start time of Biology</description> <pubDate>Tue, 13 Oct 2009 UT</pubDate> </item> ...

xpath: how can you select a specific text node before and after a <br> tag ?

consider this List of Alcohol Beer <br> Vodka <br> rum <br> whiskey how would you express Beer in xpath ? /br/preceding-sibling::text() ? what about vodka ? rum ? ...