Xpath to find all the next neighboring nodes of the cathedral to another type

Possible duplicate:
How to parse sequential tags using Nokogiri?

Can someone throw me a line?

I use ruby ​​and nokogiri to parse such a document (fragment):

... <dt>DOUE:</dt> <dd> <a href="http://ted.europa.eu">Accés al DOUE</a> - 19/07/11 </dd> <dt class="multi-linia">Criteris d'adjudicació:</dt> <dd class="info-tabulada"> <strong>Ponderació:</strong> 50.00 - <strong>Criteri:</strong> oferta econòmica </dd> <dd class="info-tabulada"> <strong>Ponderació:</strong> 40.00 - <strong>Criteri:</strong> prestacions tècniques i funcionals </dd> <dd class="info-tabulada"> <strong>Ponderació:</strong> 10.00 - <strong>Criteri:</strong> altres elements </dd> <dt>another dt now</dt> <dd>and its corresponding dd too</dd> ... 

I usually have alternate and sequential dt and dd elements. In this case, quite simple. But, as in the example, this rule is sometimes interrupted by more than one dd element between dt elements.

To analyze this list, I have an area named var pointing to this list, and I do this:

 area.search("dt").each do |dt| dd=dt.search("./following-sibling::dd[1]/text()") puts "#{clear_string(dt.text)}: #{clear_string(dd.text)}" end 

where clear_string() is a simple function that removes unnecessary spaces.

In parsing, I would like to link the dt text with the following dd text until the next dt. BTW, in the case of dd elements, I only want to save its text, and not its children. How can I do it?

+1
source share

Source: https://habr.com/ru/post/1386145/


All Articles