Reputation: 1
My monitoring application reads only if the XML is presented as elements. But my source application is only providing JSON outputs. I tried to convert the JSON output to XML using the following perl code:
# Capture the API output
if ($ApiResponse->is_error())
{
my $errorMsg = $ApiResponse->status_line();
print "error : $errorMsg\n Sending Connectivity Error\n";
}
elsif ($ApiResponse->is_success())
{
my $JSONOutput = JSON->new->utf8->convert_blessed(1)->decode($ApiResponse->content());
my $XMLOutput = XMLout($JSONOutput);
}
My output XML looks like
<opt>
<rowset affectedRows="444" dbname="custom" osname="SOMNI" tblname="tsiobm">
<rows FirstOccurrence="1594021452" Node="host" RowSerial="250" Serial="98567869" Severity="5" Summary="SDV134E TWS JOB=A76DT803 JOB04878 WS=PROD APPL=A76DT80S ERROR=JCL ID=DT803" Status="20" Prob_nr="SDV134E" />
<rows FirstOccurrence="1594130034" Node="router-ess-vpn.elber.west" RowSerial="329" Serial="98639905" Severity="5" Summary="Tunnel2 Default Interface Ping/Default Interface Ping fail for 10.23.9.5: ICMP timeout" Status="20" Prob_nr="SDV_IDWN" />
<rows FirstOccurrence="1594126166" Node="host" RowSerial="327" Serial="98637375" Severity="5" Summary="+SDV131E U00PR T09R905V 03:05:07 ACICSN1 RACINITI T09R9 STCOPC" Status="20" Prob_nr="SDV131E" />
<rows FirstOccurrence="1594012257" Node="upjbxs1_adapter_9128" RowSerial="233" Serial="98561743" Severity="5" Summary="HTTP::Globo::Webserver: CRITICAL; Details: Fehler aufgetreten! - 3/3 " Status="20" Prob_nr="GSA_HTTP_Status" />
</rowset>
</opt>
How can I get the output in elements and not attributes. Its necessary for the monitoring to work?
Upvotes: 0
Views: 73
Reputation: 1
Thank you, I realized how complicated XML::Simple is, will not use it hence forth. But for now, changing XMLout($JSONOutput) to XMLout($JSONOutput, NoAttr => 1) gave me the output as elements.
Upvotes: 0
Reputation: 385996
XML::Simple is horrible module. Its own documentation advises you to avoid it!
XML::Simple is the most complex-to-use XML parser available, and that's assuming it can even do what you want it to do. When it comes to generating XML, it is tragically hopeless
Use XML::Writer or something.
Upvotes: 1