in reply to Replace empty alt tag on <img> tag
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $input = '<image href = "images/cron1.png"><alt></alt></image>'; my $dom = 'XML::LibXML'->load_xml(string => $input); for my $alt ($dom->findnodes('//image/alt[not(text())]')) { $alt->parentNode->removeChild($alt); } print $dom;
or the less verbose wrapper XML::XSH2:
open file.xml ; rm //image/alt[not(text())] ; save :b ;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Replace empty alt tag on <img> tag
by vlearner (Initiate) on Jan 20, 2022 at 12:06 UTC | |
by choroba (Cardinal) on Jan 20, 2022 at 12:18 UTC | |
by The Perlman (Scribe) on Jan 20, 2022 at 16:42 UTC | |
by Fletch (Bishop) on Jan 20, 2022 at 19:32 UTC | |
by Anonymous Monk on Jan 20, 2022 at 18:25 UTC | |
by Discipulus (Canon) on Jan 20, 2022 at 12:17 UTC | |
by eyepopslikeamosquito (Archbishop) on Jan 20, 2022 at 22:23 UTC | |
by LanX (Saint) on Jan 21, 2022 at 00:03 UTC |