Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: hashref with(out) arrays

by haukex (Archbishop)
on Nov 21, 2017 at 15:36 UTC ( [id://1203896]=note: print w/replies, xml ) Need Help??


in reply to Re: hashref with(out) arrays
in thread hashref with(out) arrays

I have to caution against XML::Simple, it is really only still useful for reading very simple XML files, and its output is often unreliable - exactly the issue you were asking about in the root node may pop up again later, and often in a way that you can't get rid of it with a configuration option. And I have to very strongly recommend against using that module for any kind of XML writing for the same reason. XML::Simple's own documentation recommends against its use (see the section "Status of this Module"), and see also XML::Simple needs to go!

I have successfully used XML::Rules as a replacement for XML::Simple several times, for example as I showed here. Once you get into how to configure it, you can produce data structures that look like the output of XML::Simple, but are much more robust (Update: their generation and layout, not the structures themselves). I have noticed that unfortunately the module is not perfect when writing/round-tripping XML files.

Although I haven't worked with it much myself, another module is XML::Compile, which is useful if you have an XML Schema for your XML. The module takes a little bit of setting up, but once it's working, AFAICT so far it seems to be quite reliable.

And in general there are lots of other good XML processing modules, for example XML::LibXML and XML::Twig are two good ones. The above two just help in producing Perl data structures similar to what XML::Simple does.

Replies are listed 'Best First'.
Re^3: hashref with(out) arrays
by Jenda (Abbot) on Nov 27, 2017 at 14:08 UTC

    If you plan to roundtrip and need the result to look like the original (except for the changed data of course) you may have to resort to using the "raw" and "raw extended" rules and/or use a data structure that maps to the right XML. The data structure produced by the module doesn't keep any extra information about the XML it results from and the XML produced from a data structure is the "least complex one that can hold the data". You have to be a bit careful to roundtrip successfully. :-)

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1203896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found