tags:

views:

53

answers:

1

I write the following (DOM) Perl script (shown below) in order to create the following XML DOM:

 <books>
 <computer/>
 </books>

How can I save the XML output into test.xml file? I tried to save the XML with

 $doc->printToFile('/tmp/test.xml'); 

but I get:

can't locate object method "printToFile" via package "XML::LibXML::Document"

The Perl script:

 #!/usr/bin/perl

 use XML::LibXML;
 my $doc;
 $doc = XML::LibXML::Document->new;

 my $objbooks = $doc->createElement('books');
 $doc->appendChild($objbooks);

 my $objcomputer = $doc->createElement('computer');
 $objbooks->appendChild($objcomputer);
+2  A: 

I think you want XML::LibXML::Document::toFile:

 $state = $doc->toFile($filename, $format);

This function is similar to toString(), but it writes the document directly into a filesystem. This function is very useful, if one needs to store large documents.

The format parameter has the same behaviour as in toString().

JSBangs
@yael, are you getting an error message?
JSBangs
hi again , I add the $doc->toFile('/tmp/test.xml'); , after that , test.xml was created but without the element lines as <books> <computer> .... ?? why
yael