Hello Perl Monks! I have an XML file similar to the following:
<booklist>
<book>
<author>Book 1 author 1</author>
<author>Book 1 author 2</author>
<title>Book 1 title</title>
<isbn>Book1ISBN</isbn>
</book>
<book>
<author>Book 2 author 1</author>
<author>Book 2 author 2</author>
<title>Book 2 title</title>
<isbn>Book2ISBN</isbn>
</book>
<book>
<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>
I would like to loop through this file and output each book's XML code including the opening and closing book tags. I've tried parsing the XML file with XML::Simple using XMLin and that gives me a data structure like so:
$VAR1 = {
'book' => [
{
'isbn' => 'Book1ISBN',
'title' => 'Book 1 title',
'author' => [
'Book 1 author 1',
'Book 1 author 2'
]
},
{
'isbn' => 'Book2ISBN',
'title' => 'Book 2 title',
'author' => [
'Book 2 author 1',
'Book 2 author 2'
]
},
{
'isbn' => 'Book3ISBN',
'title' => 'Book 3 title',
'author' => [
'Book 3 author 1',
'Book 3 author 2',
'Book 3 author 3'
]
}
]
};
I'm really at a loss as how I would loop throught this to output the XML. I think the data structure is confusing me. I need the XML chunks to be identical to the input. I'm assuming I would use XMLout. Or maybe something completely different? Thanks in advance for any pointers!