Reputation: 173
I'm reading some content from an XML file which has the following links in it:
<wcm:root xmlns:wcm="http://www.stellent.com/wcm-data/ns/8.0.0" version="8.0.0.0">
<wcm:element name="NotesToEditors">
<a href="ssNODE/something">Something</a>
<a href="ssNODE/hello">hello</a>
<a href="https//:www.linkkkk.com">linkkkk</a>
</wcm:element>
Reading the file:
page_notes_to_editors = doc.xpath("/wcm:root/wcm:element[@name='NotesToEditors']").inner_text
Performing clean up:
notes = Nokogiri::XML.fragment(page_notes_to_editors)
notes.css('a[href="ssNODE]')
.each{|a| a.replace("<p>#{a.content}</p>")}
I tried escaping the double quote like this:
notes.css(a["href=\"ssNODE]")
It still complains.
But this does not work when the string has weird characters in. This is the error I get:
`on_error': unexpected '"' after 'equal'
My desired result is to convert ssNODE
links to paragraphs keeping its text.
Any one has any suggestions on how to achieve my desired result?
Upvotes: 0
Views: 55
Reputation: 118271
In the code notes.css('a[href="ssNODE]')
you missed the "
. Write it as notes.css('a[href^="ssNODE"]')
Documented here CSS [attribute^=value] Selector
The
[attribute^=value]
selector matches every element whose attribute value begins with a specified value.
Upvotes: 1