Perl xml convert to word document?



I am parsing xml document, i want to convert the xml content to word normal content without any tag.


example: xml file:



<title>Introduction</title>
<sec>Welcome to this world</sec>
<ref>Conclusion</ref>


Convert to word:



Introduction
Welcome to this world
Conclusion


please give any suggestion thanks in advance.


I have tried this code but it write the content what in xml file exactly.



use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 2; # Throw Errors, I'll catch them
use Cwd;
use File::Basename;
system 'cls';
#use strict;
use List::Uniq ':all';
use Sort::Versions;
my $xmlfile = 'D:\file.xml';
my $cnt = _open_utf8($xmlfile);
my $dir = dirname($xmlfile);
my $basename = basename($xmlfile);
my $wordsave = Win32::OLE->new('Word.Application', 'Quit') or die;
$wordsave->{Visible} = 1;
my $doc = $wordsave->Documents->Add();
my $range = $doc->{Content};
### insert some text into the document
$range->{Text} = $cnt;
### read text from the document and print to the console
my $paras = $doc->Paragraphs;
foreach my $para (in $paras) {
print ">> " . $para->Range->{Text};
}
### close the document and the application
$doc->SaveAs(FileName => 'd:\temp.docx', FileFormat => wdFormatDocument);
$doc->Close();
$wordsave->Quit();
_save_utf8($dir.'\\out_'.$basename,$cnt);

No comments:

Post a Comment