Hi,

Sorry to bother you again.
I am trying to create from sratch an XML file.
Base on the Xerces perl exemple (whichi seems to be old and not really running) and Xerces C++ ducumentation I write the following code:


#### Create a document
my $impl = XML::Xerces::DOMImplementationRegistry::getDOMImplementation("CORE");
my $serializer = $impl->createDOMWriter();



my $dt = eval{$impl->createDocumentType('contributors', '', 'contributors.dtd')};
error($@) if $@;
my $doc = eval{$impl->createDocument('contributors', 'contributors',$dt)};
error($@) if $@;


$serializer->setFeature("$XML::Xerces::fgDOMWRTFormatPrettyPrint", 1);

This line give me an error:
XML::Xerces::DOMException=HASH(0x8469214)
I can live without that but I wanted to try to have a nice ouput file.

my $root = $doc->getDocumentElement();

$root->appendChild(main::CreatePerson( $doc,
'Mike Pogue',
'manager',
'[EMAIL PROTECTED]'
));


$root->appendChild(main::CreatePerson(
                 $doc,
                 'Tom Watson',
                 'developer',
   '[EMAIL PROTECTED]'
                ));

$root->appendChild(main::CreatePerson(
                 $doc,
                 'Susan Hardenbrook',
                 'tech writer',
                 '[EMAIL PROTECTED]'
                ));

my $str = $serializer->writeToString($root);

Here I would like to write to a file directly but I haven't found the equivanlent in Perl of the LocalFileFormatTarget C++ class to use in writeNode() function.
But I can write my string to a file with Perl features.
By my string is all on one line:


<contributors xmlns="contributors"><person Role="manager"><name>Mike Pogue</name><email>[EMAIL PROTECTED]</email></person><person Role="developer"><name>Tom Watson</name><email>[EMAIL PROTECTED]</email></person><person Role="tech writer"><name>Susan Hardenbrook</name><email>[EMAIL PROTECTED]</email></person></contributors>

How can I format it with Xerces Perl in order to have an indented XML (has if is was written through emacs for example) ?
Is there better way to do what I want than the code I did ?
Thanks for you help


Take care

Christian



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to