xerces-p-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Orsatti <orsa...@istar.fr>
Subject Create and writean XML file
Date Thu, 30 Oct 2003 14:25:38 GMT
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',
                  'mpogue@us.ibm.com'
                 ));

$root->appendChild(main::CreatePerson(
                  $doc,
                  'Tom Watson',
                  'developer',
    'rtwatson@us.ibm.com'
                 ));

$root->appendChild(main::CreatePerson(
                  $doc,
                  'Susan Hardenbrook',
                  'tech writer',
                  'susanhar@us.ibm.com'
                 ));

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>mpogue@us.ibm.com</email></person><person 
Role="developer"><name>Tom 
Watson</name><email>rtwatson@us.ibm.com</email></person><person

Role="tech writer"><name>Susan 
Hardenbrook</name><email>susanhar@us.ibm.com</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: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Mime
View raw message