I recently used XML::Simple for something very similar. You just tell it to read
your xml file and it'll parse it up and create a handy data structure to work with.

Use it with Data::Dumper if you want to see how it handles your xml:

################

#!/usr/local/bin/perl -w

use Data::Dumper;
use XML::Simple;
use strict;
my $xml = XMLin('your_xml_file.xml');
print Dumper($xml);

################

Regards,
Matt







Regards,
Matt


--- VitolD <[EMAIL PROTECTED]> wrote:
> Hello everyone!
> 
> It's my first expirience with XML.
> 
> I have simple XML document like this
> <?xml version="1.0"?>
> <site>
>   <section id='1'>
>     <page id='11' />
>   </section>
>   <page id='00' />
>   <section id='2'>
>     <page id='22' />
>       <section id='3'>
>         <page id='33' />
>       </section>
>   </section>
>   <page id='44' />
> </site>
> 
> And I need to produce something like this
> 
> ========================================
> ...... something like header here ......
> ........ root is 'site' ................
> 
> 'section', id=1 (parent = 'site')
> 'page', id=11 (parent = 'section', id=1)
> 'page', id=00 (parent = 'site')
> 'section', id=2 (parent = 'site')
> 'page', id=22 (parent = 'section', id=2)
> 'section', id=3 (parent = 'section', id=2)
> 'page', id=33 (parent = 'section', id=3)
> 
> ...... something like footer here ......
> ........................................
> ========================================
> 
> How can I do it with siplest way?
> 
> 
> I've been trying to make this with XML::Parser::Expat,
> my $parser = new XML::Parser::Expat;
> $parser->setHandlers(Start => \&start);
> $parser->parsefile($file);
> 
> sub start {
>   my ($p, $el, %atts) = @_;
>   print "'$el', id=$atts{id} (parent = $current_element, id=????";
> }
> 
> But in this case I can't know attributes of parent node... How can I know
> this?
> May be there are another better ways to solve my problem?
> 
> Many many thanks for your attention!!!
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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

Reply via email to