"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>


Reply via email to