1

I have to convert HTML fragments built in the Radiant CMS to a new format. This requires parsing HTML and "R-Tags" that look like this:

<r:asset:image size="original" align="right" id="3445" hspace="20" width="300"/>
<r:profile:link id="815">Henry Trudeau</r:profile:link>

I can't figure out how to query for these elements with Nokogiri. I tried:

fragment = Nokogiri::HTML.fragment(content)
fragment.xpath(".//r:asset:image")
# Nokogiri::XML::XPath::SyntaxError: ERROR: Undefined namespace prefix: .//r:asset:image

and

fragment.css("r|asset|image")
# Nokogiri::CSS::SyntaxError: unexpected '|' after '[#<Nokogiri::CSS::Node:0x0056494e6891e0 @type=:ELEMENT_NAME, @value=["r:asset"]>]'
4

0 回答 0