Hi there,
I'm new to XML and having a hard time with below.
here is my original XML data:
<productidentifier>
<b221>02</b221>
<b244>0123456789</b244>
</productidentifier>
<productidentifier>
<b221>03</b221>
<b244>9780123456789</b244>
</productidentifier>
<othertext>
<d102>02</d102>
<d103>02</d103>
<d104><![CDATA[<div>book synopsis. <br></div>]]></d104>
</othertext>
<othertext>
<d102>04</d102>
<d103>02</d103>
<d104><![CDATA[<div>Table of Contents. <br></div>]]></d104>
</othertext>
<othertext>
<d102>08</d102>
<d103>02</d103>
<d104><![CDATA[<div>``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br></div>]]></d104>
</othertext>
<othertext>
<d102>08</d102>
<d103>02</d103>
<d104><![CDATA[<div>"book review blah blah blah' --<i>Joe Journal</i> <br></div>]]></d104>
</othertext>
<othertext>
<d102>13</d102>
<d103>02</d103>
<d104><![CDATA[<div><div>Author biography blah blah blah.</div></div>]]></d104>
</othertext>
Now here's the output I get back with below code:
========================
OUTPUT
========================
'othertext' => [
{
'd103' => '02',
'd102' => '02',
'd104' => '<div>book synopsis. <br></div>'
},
{
'd103' => '02',
'd102' => '04',
'd104' => '<div>Table of Contents. <br></div>'
},
{
'd103' => '02',
'd102' => '08',
'd104' => '<div>``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br></div>'
},
{
'd103' => '02',
'd102' => '08',
'd104' => '<div>"book review blah blah blah' --<i>Joe Journal</i> <br></div>'
},
{
'd103' => '02',
'd102' => '13',
'd104' => '<div><div>Author biography blah blah blah.</div></div>'
}
],
'productidentifier' => [
{
'b221' => '02',
'b244' => '0898624347'
},
{
'b221' => '03',
'b244' => '9780898624342'
}
];
==============================================
How would I edit above code so as to get only the following values in my output?
9780123456789
<d102>02</d102>
book synopsis. <br>
<d102>04</d102>
Table of Contents. <br>
<d102>08</d102>
``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br>
<d102>08</d102>
"book review blah blah blah' --<i>Joe Journal</i> <br>
<d102>13</d102>
Author biography blah blah blah.
thanks.
I'm new to XML and having a hard time with below.
here is my original XML data:
<productidentifier>
<b221>02</b221>
<b244>0123456789</b244>
</productidentifier>
<productidentifier>
<b221>03</b221>
<b244>9780123456789</b244>
</productidentifier>
<othertext>
<d102>02</d102>
<d103>02</d103>
<d104><![CDATA[<div>book synopsis. <br></div>]]></d104>
</othertext>
<othertext>
<d102>04</d102>
<d103>02</d103>
<d104><![CDATA[<div>Table of Contents. <br></div>]]></d104>
</othertext>
<othertext>
<d102>08</d102>
<d103>02</d103>
<d104><![CDATA[<div>``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br></div>]]></d104>
</othertext>
<othertext>
<d102>08</d102>
<d103>02</d103>
<d104><![CDATA[<div>"book review blah blah blah' --<i>Joe Journal</i> <br></div>]]></d104>
</othertext>
<othertext>
<d102>13</d102>
<d103>02</d103>
<d104><![CDATA[<div><div>Author biography blah blah blah.</div></div>]]></d104>
</othertext>
Now here's the output I get back with below code:
Code:
use strict;
use XML::Simple;
use Data::Dumper;
#create object
our $xml = new XML::Simple;
#open output file
open OUTPUT, ">xml_output.txt";
#read XML file
our $data = $xml->XMLin("xml_test_file.xml");
#dereference hash ref
print OUTPUT Dumper($data);
print Dumper($data);
close OUTPUT;
========================
OUTPUT
========================
'othertext' => [
{
'd103' => '02',
'd102' => '02',
'd104' => '<div>book synopsis. <br></div>'
},
{
'd103' => '02',
'd102' => '04',
'd104' => '<div>Table of Contents. <br></div>'
},
{
'd103' => '02',
'd102' => '08',
'd104' => '<div>``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br></div>'
},
{
'd103' => '02',
'd102' => '08',
'd104' => '<div>"book review blah blah blah' --<i>Joe Journal</i> <br></div>'
},
{
'd103' => '02',
'd102' => '13',
'd104' => '<div><div>Author biography blah blah blah.</div></div>'
}
],
'productidentifier' => [
{
'b221' => '02',
'b244' => '0898624347'
},
{
'b221' => '03',
'b244' => '9780898624342'
}
];
==============================================
How would I edit above code so as to get only the following values in my output?
9780123456789
<d102>02</d102>
book synopsis. <br>
<d102>04</d102>
Table of Contents. <br>
<d102>08</d102>
``book review blah blah blah.'--Jane Doe, Ph.D.,<br>University of blah blah blah <br>
<d102>08</d102>
"book review blah blah blah' --<i>Joe Journal</i> <br>
<d102>13</d102>
Author biography blah blah blah.
thanks.