Removing anything between XML tags and their content

后端 未结 5 1910
无人及你
无人及你 2021-01-07 04:40

I would need to remove anything between XML tags, especially whitespace and newlines.

For example removing whitespace and newslines from:
\\n<

5条回答
  •  长情又很酷
    2021-01-07 04:42

    A solution is to select all "blank" text nodes and remove them.

    doc = Nokogiri(xml_source)
    doc.xpath('//text()[not(normalize-space())]').remove
    

提交回复
热议问题