Hi Robin,
yeah I have looked at documentation of XML::Writer.
The example explains how to create a new xml file
and insert tags there, but does not says how to modify
already existing XML.
My problem is I want to read and write into the same
xml file.For reader I am using XML::SimpleObject and
and for writing XML::Writer.
Both of them uses separate objects.
I want to pass the XML(used by XML::SimpleObject) to the writer
object for modification, so that I can do some write operation.
Any pointers also is fine.
Thanx,
Alok
-----Original Message-----
From: Robin Norwood [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 09, 2006 8:23 PM
To: Nath, Alok (STSD)
Cc: [email protected]
Subject: Re: Writing to XML using XML::Writer
"Nath, Alok (STSD)" <[EMAIL PROTECTED]> writes:
> Hi,
> Can anybody give me a simple code snippet which writes or
modifies
> this xml ?
>
> <my_list>
> <guy name="SomeGuy">
> <user>Tom</user>
> <date-of-birth>Aug 2006</date-of-birth>
> </guy>
> <guy name="AnotherGuy">
> <user>Dicken</user>
> <date-of-birth>Aug 2006</date-of-birth>
> </guy>
> </my_list>
>
> I want to read and write into this simple xml, basically
changing the
> values or deleting them.
> After scanning through different XML modules I zeroed into
> XML::SimpleObject for reading.For
> reading I know how to do it.For writing I am struggling.I want
to use
> XML::Writer.
>
> Any help greatly appreciated.
Well...have you looked at perldoc XML::Writer ? The module is pretty
well documented...if you start with the hello world example in the docs,
you should be able to get to your example with a few minutes of hacking.
If you have any problems with it, don't hesitate to ask.
-RN
> Thanx,
> Alok
>
> use XML::Parser ;
> use XML::SimpleObject;
> use XML::Writer;
> use IO::File;
>
>
> my $xml = "Inventory.xml" ;
>
> my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree"); my
> $xso = XML::SimpleObject->new( $parser->parsefile($xml) );
>
> # Reading an XML file
> foreach my $element ($xso->child("my_list")->children("guy"))
> {
> print " User: " . $element->child("user")->value . "\n";
>
> print " Date of Birth: " .
> $element->child("date-of-birth")->value . "\n";
>
> print "\n" ;
> }
>
> # Code for Writing into the above xml
--
Robin Norwood
Red Hat, Inc.
"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>