Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
what's wrong with following code?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dec  
View profile  
 More options Jun 16 2011, 10:49 am
From: Dec <jiaode...@gmail.com>
Date: Thu, 16 Jun 2011 07:49:03 -0700 (PDT)
Local: Thurs, Jun 16 2011 10:49 am
Subject: what's wrong with following code?
====
require 'nokogiri'
xml  = Nokogiri::XML("<a><b><c>Test 1</c></b><b><c>Test 2</c></
b><b><c>Test 3</b></c></a>")

 xml.search("//b").each do |b|
        b.at("//c").content = b.at("//c").content + " B"
end
puts xml

====

I'm expecting to get "B" appended to each <c> element, but get output
like this:
======
<?xml version="1.0"?>
<a>
  <b>
    <c>Test 1 B B B</c>
  </b>
  <b>
    <c>Test 2</c>
  </b>
  <b>
    <c>Test 3</c>
  </b>
</a>
===============


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Dalessio  
View profile  
 More options Jun 16 2011, 12:04 pm
From: Mike Dalessio <mike.dales...@gmail.com>
Date: Thu, 16 Jun 2011 12:04:20 -0400
Local: Thurs, Jun 16 2011 12:04 pm
Subject: Re: [nokogiri-talk] what's wrong with following code?

Hello,

In Xpath, a initial slash in your search string says "start at the top of
the document." You want to start at the context node, so use "./" like so:

    xml.search("//b").each do |b|
      b.at("./c").content = b.at("./c").content + " B"
    end

Or save the extra XPath query and write:

    xml.search("//b").each do |b|
      b.at("./c").content += " B"
    end

---
mike dalessio / @flavorjones


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »