Click here to get back home

get rid of non xml compliant lines from a file

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
get rid of non xml compliant lines from a file Mr_Noob 03-26-2008
Posted by Mr_Noob on March 26, 2008, 6:00 am
Please log in for more thread options
Hi all,

I try to write a perl script that would delete all non xml complient
lines (ie beginning with "<" and ending ">").
Here is what i succeded to put down so far :


sub delete_non_xml_lines
{
        my $search = new File::List($xmldir);
        my @files = @{ $search->find("textfile") };

        foreach (@files)
        {
                my $file = $_;
                open(FILE, "< $file") or die "Can't open $file : $!";
                while(<FILE>)
                {
                        print if $_ =~ />$/;
                }
                close FILE;
        }
}


But how can I redirect the output for each processed file into an xml
file ?

thanks in advance for helping

Regards

Posted by RedGrittyBrick on March 26, 2008, 7:00 am
Please log in for more thread options
Mr_Noob wrote:
>
> I try to write a perl script that would delete all non xml complient
> lines (ie beginning with "<" and ending ">").

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
<article>
<sect1>
<title>Observations on XML structure</title>
<para>This is a valid XML document.
Most of the lines don't start with an &lt; symbol.
Some of the lines don't end with an &gt; symbol.
Yet it is still valid XML.</para>
</sect1>
</article>

--
RGB

Similar ThreadsPosted
Kindly help :::How can I send the output of the system() command to a file and capture a string in one of the lines in that file June 19, 2005, 1:40 pm
Program for retrieving certain lines in a file and writing them to another file July 21, 2005, 12:56 pm
XML 1.1 parser, compliant in Perl April 11, 2006, 9:12 pm
Delete lines in a file December 1, 2004, 8:46 am
sed/grep out lines in file January 21, 2007, 9:56 pm
find lines in a file February 6, 2007, 2:56 pm
How to get some specify lines in a block of a file? September 28, 2007, 4:19 am
Reading last N lines from large file November 25, 2004, 3:51 pm
FAQ 5.3: How do I count the number of lines in a file? December 4, 2004, 6:03 am
FAQ 5.3: How do I count the number of lines in a file? January 6, 2005, 12:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap