title: nokogiri: how to wrap html tags around given xpath elements?
body: <p>I have an xpath to grab each text node which is not surrounded by any html tags. Instead, they are separated via <code>&lt;br&gt;</code>. I would like to wrap these with <code>&lt;span&gt;</code> tags.</p>
  
  <pre><code>Nokogiri::HTML(open("http://vancouver.en.craigslist.ca/van/swp/1426164969.html"))
  .xpath("//br/following-sibling::text()|//br/preceding-sibling::text()").to_a
  </code></pre>
  
  <p>will return those text nodes.</p>
  
  <p>complete revised code below:</p>
  
  <pre><code>doc = Nokogiri::HTML(open("http://vancouver.en.craigslist.ca/van/swp/1426164969.html"))
  .xpath("//br/following-sibling::text()|//br/preceding-sibling::text()").wrap("&lt;span&gt;&lt;/span&gt;")
  puts doc
  </code></pre>
  
  <p>I expected to see a full html source code with those texts wrapped with <code>&lt;span&gt;</code> tags, but I got the following:</p>
  
  <pre><code>Date: 2009-10-17,  4:36PM PDT
  Reply to:
  This is a spectacular open plan 1000 sq. ft. loft is in a former Canada Post building. Upon entering the loft from the hallway you are amazed at where you have arrived.... a stunning, bright and fully renovated apartment that retains its industrial feel. The restoration of the interior was planned and designed by a famous Vancouver architect.
  The loft is above a police station, so youÂre guaranteed peace and quite at any time of the day or night.
  The neighborhood is safe and lively with plenty of restaurants and shopping. ThereÂs a starbucks across the street and plenty of other coffee shops in the area.  Antique alley with its hidden treasures is one block away, as well as the beautiful mile long boardwalk. Skytrain station is one minute away (literally couple of buildings away). 15 minutes to Commercial drive, 20 minutes to downtown Vancouver and Olympic venues.
  Apartment Features:
  -       Fully furnished
  -       14 ft ceilings
  -       Hardwood floors
  -       Gas fireplace
  -       Elevator
  -       Large rooftop balcony
  -       Full Kitchen: Fully equipped with crystal, china and utensils
  -       Dishwasher
  -       Appliances including high-end juice maker, blender, etc.
  -       WiFi (Wireless Internet)
  -       Bathtub
  -       Linens &amp;amp; towels provided
  -       Hair dryer
  -       LCD Flat-screen TV with DVD player
  -       Extensive DVD library
  -       Music Library: Ipod connection
  -       Wii console with Guitar Hero, games
  -       Book and magazine library
  -       Non-smoking
  We are looking to exchange for a place somewhere warm (California, Hawaii, Mexico, South America, Central America) or a place in Europe (UK, Italy, France).
  Email for other dates and pictures of the loft.
  </code></pre>