dominic01 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to convert a XML into JSON. I am converting XML into a Hashref and then using JSON::Any to JSON. I am struck in the first part i.e. XML to HashRef. My source XML
I tried with XML::Simple<Publisher> <UniqueDOI>978-3-642-123456</UniqueDOI> <ChapterInfo ChapterType="OriginalPaper"> <Title Language="En">Is Light Blue (<Emphasis Type="Italic">azzurr +o</Emphasis>) Color Name Universal in the Italian Language?</Title> </ChapterInfo> </Publisher>
Using XML::LibXML::Simpleuse XML::Simple; use Data::Dumper; my $XMLRef = XMLin('new.xml'); print Dumper $XMLRef;
Using XML::Twiguse XML::LibXML::Simple (); use Data::Dumper; my $xs = XML::LibXML::Simple->new(%options); my $XMLRef = $xs->XMLin('new.xml'); print Dumper $XMLRef;
use XML::Twig; use Data::Dumper; my $twig=XML::Twig->new(); my $XMLRef = $twig->parsefile( 'new.xml' )->simplify(); print Dumper $XMLRef;
Update: All the above scripts are NOT properly converting the child "Emphasis". The error part of the dump is more or less similar to
Is it possible to do like (leave specific tags as it is)'ChapterTitle' => { 'Emphasis' => { 'Type' => 'Italic', 'content' => 'azzurro }, 'Language' => 'En', 'content' => [ 'Is Light Blue (', ') Color Name Univeral in the Italian Language?' ] },
'ChapterTitle' => { 'Language' => 'En', 'content' => [ 'Is Light Blue (<Emphasis Type="Italic">azzurro</Emphasis>) Co +lor Name Univeral in the Italian Language?' ] },
I appreciate any pointers in this regard.
Regards Dominic
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML to HashRef and then to JSON
by Corion (Patriarch) on Mar 14, 2016 at 16:04 UTC | |
|
Re: XML to HashRef and then to JSON
by tangent (Parson) on Mar 15, 2016 at 01:18 UTC | |
by dominic01 (Sexton) on Mar 15, 2016 at 05:07 UTC | |
|
Re: XML to HashRef and then to JSON
by LanX (Saint) on Mar 14, 2016 at 16:11 UTC | |
by Anonymous Monk on Mar 14, 2016 at 16:13 UTC | |
|
Re: XML to HashRef and then to JSON
by Jenda (Abbot) on Mar 17, 2016 at 17:30 UTC |