From: Phlip Date: 2009-03-19T04:37:25+09:00 Subject: Re: REXML get specific element 7stud -- wrote: > That doesn't work for me. And I couldn't figure out the escaping > necessary to handle both a name entered with a single quote or a double > quote. I thought I understood ruby escaping, but not anymore. You understand Ruby escaping - just not XPath escaping. There is none. If you use ' to delimit a string, you cannot use ' inside it. I would love to be proven wrong, but I did research this for quite a while. Why didn't my $name substitution work? It's in the rdocs... > f = File.new('xml4.xml') > doc = Document.new(f) > > input_name = gets > input_name = input_name.chomp > > target = XPath.match(doc, "//programmer[text() = 'John']") > puts target[0].attributes["age"] Wouldn't this work? target = XPath.match(doc, "//programmer[text() = $name]", :name => $john) > input_name = input_name.gsub("'", "\\'") > p input_name > > --output:-- > "Joh'n" > "Johnn" > > Can anyone explain what's going on there? XPath does not escape ticks with \.