Re: Writing XML from Perl

2002-10-24 Thread Kris Boulez
Quoting Dominic Mitchell ([EMAIL PROTECTED]):

[ ... ]

Hereby I want to thank everyone for their suggestions. I'll have a look
at the different options and make an educated choice.

> 
> The important point is to not use print statements, because you'll get 
> it wrong.  :-)
> 
I did this for a project a few years ago and this was o so true :)

Kris,
-- 
Kris Boulez Tel: +32-9-241.11.00
AlgoNomics NV   Fax: +32-9-241.11.02
Technologiepark 4   email: [EMAIL PROTECTED]
B 9052 Zwijnaarde   http://www.algonomics.com/




Re: Writing XML from Perl

2002-10-24 Thread Dominic Mitchell
Marty Pauley wrote:

On Thu Oct 24 15:13:09 2002, Kris Boulez wrote:


What is peoples preferred module for writing XML (files) from within
Perl ? The data is read by a perl script from different (heterogeneous) 
sources and stored internally in a tree of objects.


I use XML::DOM for that sort of thing.  I haven't tried anything else
since XML::DOM has worked well.  As I walk the tree each node calls
createElement for itself then appendChild for any branches.


XML::LibXML (as mentioned in another post) is likely to be a lot 
quicker, as it's based on a C library.

Personally, I use either XML::Twig, or XML::SAX::Writer, as appropriate.

The important point is to not use print statements, because you'll get 
it wrong.  :-)

-Dom

--
| Semantico: creators of major online resources  |
|   URL: http://www.semantico.com/   |
|   Tel: +44 (1273) 72   |
|   Address: 33 Bond St., Brighton, Sussex, BN1 1RD, UK. |



Re: Writing XML from Perl

2002-10-24 Thread Ben
On Thu, Oct 24, 2002 at 05:16:13PM +0100, Dominic Mitchell wrote:
> Marty Pauley wrote:
> > On Thu Oct 24 15:13:09 2002, Kris Boulez wrote:
> > 
> >>What is peoples preferred module for writing XML (files) from within
> >>Perl ? The data is read by a perl script from different (heterogeneous) 
> >>sources and stored internally in a tree of objects.
> > 
> > 
> > I use XML::DOM for that sort of thing.  I haven't tried anything else
> > since XML::DOM has worked well.  As I walk the tree each node calls
> > createElement for itself then appendChild for any branches.
> 
> XML::LibXML (as mentioned in another post) is likely to be a lot 
> quicker, as it's based on a C library.

XML::GDOM has a partially or totally SAX2 compatability, is based on libxml2
and has a virtually drop-in replacement interface for XML::DOM.

It was what I used the last time I did any XML. But then, I hate XML.

Ben




Re: Writing XML from Perl

2002-10-24 Thread Mark Fowler
On Thu, 24 Oct 2002, Kris Boulez wrote:

> What is peoples preferred module for writing XML (files) from within
> Perl ? The data is read by a perl script from different (heterogeneous) 
> sources and stored internally in a tree of objects.

The prefered way is to make calls to XML::SAX to output the data, but 
"prefered" is a very vauge term.  You might want to use one of the SAX 
drivers that use perl data structures since you've already got one.  Or it 
might be simpler to use a differnt module all together as you're only 
dealing with files...

To be honest, this is a bit of an open ended question, and, well, there's 
more than one way to do it.  I recommend:

 a) Reading Perl & XML (o'reilly) (also part of perl cd bookshelf 3)
 b) Reading all of Kip's articles on xml.com [1]
 c) Joining the perl XML mailing list [2]
 d) Asking people on #axkit / #axkit-dahut [3]

Hope that's helpful.

Mark.

[1] I suggest you start here: 
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
[2] http://lists.perl.org/showlist.cgi?name=perl-xml
[3] irc.rhizomatic.net (or local node), port 6667.

-- 
s''  Mark Fowler London.pm   Bath.pm
 http://www.twoshortplanks.com/  [EMAIL PROTECTED]
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/  +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}






Re: Writing XML from Perl

2002-10-24 Thread Marty Pauley
On Thu Oct 24 15:13:09 2002, Kris Boulez wrote:
> What is peoples preferred module for writing XML (files) from within
> Perl ? The data is read by a perl script from different (heterogeneous) 
> sources and stored internally in a tree of objects.

I use XML::DOM for that sort of thing.  I haven't tried anything else
since XML::DOM has worked well.  As I walk the tree each node calls
createElement for itself then appendChild for any branches.

-- 
Marty




Re: Writing XML from Perl

2002-10-24 Thread Paul Golds
On Thu, Oct 24, 2002 at 03:13:09PM +0200, Kris Boulez wrote:
> What is peoples preferred module for writing XML (files) from within
> Perl ? The data is read by a perl script from different (heterogeneous) 
> sources and stored internally in a tree of objects.
> 
> I looked around a bit and saw XML::Writer being mentioned a lot. Is it
> this what most people are using ?

When I needed to write out some XML at work for reading by
someone's Java application (Not that what reads it should
matter) I had a play with XML::Writer to start with, but
kept having problems with it dumping illegal characters into
the XML.  Hmm.

Ended up using the XML::LibXML module, a very different
approach in that XML is produced as a tree and then written
out all at once rather than line-by-line.  This did have the
advantage that I can't think how I could force it to produce
invalid XML, and I had a lot less conditional logic to deal
with.  On the downside it naturally used up more memory, but
since I wasn't dealing with overly huge datafiles this
wasn't too much of an issue for me.


Paul Golds