How can I parse a diffgam.xml file with perl in a way to get array of hashes instead of a big hash-map?



I get following diffgram XML from a service:



<?xml version="1.0"?>
<xvcs:diffgram xmlns:xvcs="http://www.xvcs.org/">
<xvcs:update id="7" first-child-of="/opt/node/node[1]">
<xvcs:attr-update name="location" old-value="???" new-value="testlocation"/>
</xvcs:update>
<xvcs:update id="35" follows="/opt/node/node[2]">
<xvcs:attr-update name="URL" old-value="/" new-value="/testurl/"/>
</xvcs:update>
<xvcs:insert id="75" first-child-of="/opt">
<node node_id="/1234" location="new location" URL="/newurl"></node>
</xvcs:insert>
</xvcs:diffgram>


I'm parsing it with XML::Simple in this way:



my $diffgram_hashref = XMLin($diffgram->toString(1),
KeepRoot => 1,
ForceArray => 1,
);

$logger->debug( dump($diffgram_hashref) );


and get following result:



{
"xvcs:diffgram" => [
{
"xmlns:xvcs" => "http://www.xvcs.org/",
"xvcs:insert" => {
75 => {
"first-child-of" => "/opt",
"node" => [
{
node_id => "/1234",
location => "new location",
URL => "/newurl",
},
],
},
},
"xvcs:update" => {
7 => {
"first-child-of" => "/opt/node/node[1]",
"xvcs:attr-update" => {
location => { "new-value" => "testlocation", "old-value" => "???" },
},
},
35 => {
"follows" => "/opt/node/node[2]",
"xvcs:attr-update" => {
URL => { "new-value" => "/testurl/", "old-value" => "/" },
},
},
},
},
],
}


I tried several ForeArray / KeyAttr combinations but I did not achieve to get the diffgram statements (update, insert) as array in order to proceed them in correct order:



{
"xvcs:diffgram" => [
{
"xvcs:update" => {
7 => {
"first-child-of" => "/opt/node/node[1]",
"xvcs:attr-update" => {
location => { "new-value" => "testlocation", "old-value" => "???" },
},
}
}
},
{
"xvcs:update" => {
35 => {
"follows" => "/opt/node/node[2]",
"xvcs:attr-update" => {
URL => { "new-value" => "/testurl/", "old-value" => "/" },
},
},
}
},
{
"xvcs:insert" => {
75 => {
"first-child-of" => "/opt",
"node" => [
{
node_id => "/1234",
location => "new location",
URL => "/newurl",
},
],
},
},
}
]
}


Could someone help me out please?


No comments:

Post a Comment