replace <img> tag's src attribute from file content in rails

佐手、 提交于 2019-12-13 03:34:30

问题


Want to replace tag's src attribute value in xhtml file content.

section_content = section.export_xhtml_content file_path
doc = Nokogiri::HTML(section_content)
unless doc.css('div.image_content').blank?
  doc.css('div.image_content img').each do |img|
    newsrc = File.basename img[:src]
    img.set_attribute('src', newsrc)
  end
end

Here src attribute get replaced. But getting XML Parsing Error: XML or text declaration not at start of entity error. After replacing src attribute, resultant content should be in xhtml. Kindly help me to solve this.

来源:https://stackoverflow.com/questions/22637833/replace-img-tags-src-attribute-from-file-content-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!