Here is my perl code to parse it:<booklist> <book type="technical"> <author>Book 1 author 1</author> <author>Book 1 author 2</author> <title>Book 1 title</title> <isbn>Book1ISBN</isbn> </book> <book type="fiction"> <author>Book 2 author 1</author> <author>Book 2 author 2</author> <title>Book 2 title</title> <isbn>Book2ISBN</isbn> </book> <book type="technical"> <author>Book 3 author 1</author> <author>Book 3 author 2</author> <author>Book 3 author 3</author> <title>Book 3 title</title> <isbn>Book3ISBN</isbn> </book> </booklist>
And here is the output:use XML::Parser; # initialize parser and read the file $parser = new XML::Parser( Style => 'Tree' ); my $tree = $parser->parsefile( shift @ARGV ); # serialize the structure use Data::Dumper; print Dumper( $tree );
HOW TO ACCESS INDIVIDUAL ELEMENTS? How will they get stored in hash table? For example, I am interested in having "type" of the book.$VAR1 = [ 'booklist', [ {}, 0, ' ', 'book', [ { 'type' => 'technical' }, 0, ' ', 'author', [ {}, 0, 'Book 1 author 1' ], 0, ' ', 'author', [ {}, 0, 'Book 1 author 2' ], 0, ' ', 'title', [ {}, 0, 'Book 1 title' ], 0, ' ', 'isbn', [ {}, 0, 'Book1ISBN' ], 0, ' ' ], 0, ' ', 'book', [ { 'type' => 'fiction' }, 0, ' ', 'author', [ {}, 0, 'Book 2 author 1' ], 0, ' ', 'author', [ {}, 0, 'Book 2 author 2' ], 0, ' ', 'title', [ {}, 0, 'Book 2 title' ], 0, ' ', 'isbn', [ {}, 0, 'Book2ISBN' ], 0, ' ' ], 0, ' ', 'book', [ { 'type' => 'technical' }, 0, ' ', 'author', [ {}, 0, 'Book 3 author 1' ], 0, ' ', 'author', [ {}, 0, 'Book 3 author 2' ], 0, ' ', 'author', [ {}, 0, 'Book 3 author 3' ], 0, ' ', 'title', [ {}, 0, 'Book 3 title' ], 0, ' ', 'isbn', [ {}, 0, 'Book3ISBN' ], 0, ' ' ], 0, ' ' ] ];
Thanks in Advance,
Uday Sagar
In reply to Accessing xml elements using XML::Parser module by uday_sagar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |