-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);
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
yael
  • 2,765
  • 10
  • 40
  • 48

1 Answers1

3

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().

Community
  • 1
  • 1
JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
  • hi again , I add the $doc->toFile('/tmp/test.xml'); , after that , test.xml was created but without the element lines as .... ?? why – yael Jul 13 '10 at 04:20