Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: XML::Simple and ISO-8859-1 encoding buggy?

by GrandFather (Saint)
on May 26, 2021 at 22:03 UTC ( #11133095=note: print w/replies, xml ) Need Help??


in reply to XML::Simple and ISO-8859-1 encoding buggy?

From the XML::Simple documentation:

SYNOPSIS

PLEASE DO NOT USE THIS MODULE IN NEW CODE. If you ignore this warning and use it anyway, the qw(:strict) mode will save you a little pain.

That doesn't directly address your conversion issue, but it does speak to the (low) likely hood of the module author fixing the problem. The last update to the module was over three years ago.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
  • Comment on Re: XML::Simple and ISO-8859-1 encoding buggy?

Replies are listed 'Best First'.
Re^2: XML::Simple and ISO-8859-1 encoding buggy?
by cavac (Curate) on May 27, 2021 at 07:43 UTC

    While that is generally true, especially for generating XML files, i have yet to find another XML parser that is as simple and easy to use. XML::Rules is somewhat promising, but still adds a lot of extra complications.

    When it comes to parsing config files, i generally don't give an f### if it validates against some XSD schema (and in usually don't bother to even create one). I don't need "sequential parsing" or "streaming" because of the file size. All i want to do is turn that file into a hashref. And i don't care about all the "advanced" XML stuff like namespaces. The only reason i'm not using JSON is because i find XML easier to read and write by hand.

    For some time now i've been thinking of either forking XML::Simple (and rip out all the "write XML files" stuff) or writing a wrapper for something like XML::Rules that emulates the XML::Simple behaviour as close as possible. In my humble opinion, we really need a module that's as simple as XML::Simple, at least for reading XML config files. Basically the equivalent of simplicity to parsing a JSON file.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
      > Basically the equivalent of simplicity to parsing a JSON file.

      The problem is the DOM tree of XML doesn't correspond 1:1 to common data structures (scalars, arrays, hashes).

      <r ch="1"> <ch>2</ch> <ch>3</ch> <!-- <ch>4</ch> --> </r>
      What data structure do you expect?

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        I expect that all of the "ch" elements in this tag will be put into an array. But what i really expect is that the XML doesn't come with such a stupid and confusing design in the first place. I can't see a semantic reason for this type of XML design. If someone sends me a design like this and does not have a very, very, very good explanation and a very solid reason behind this, i will just refuse to accept that design.

        Just because something is possible does not mean it is acceptable. Like using obfuscation in production code.

        perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

      While I personally do think XML::Simple is sometimes (but rarely!) ok to use, for reading very simple XML files that happen to be structured in a way that the module does handle well (which one can make sure of via a Schema), IMHO the major problem of XML::Simple is that it does not handle the structure of the XML file changing very well at all. Someone may start out a project with a simple XML file that the module can handle, but as the project grows and the XML's structure becomes more complex, one begins jumping through hoops to bend the data structure back into shape. Another problem is that the module's name lends itself to the misunderstanding that it's a simple way to read arbitrary XML files, which is most certainly not the case. Both of these cases are well-represented across various threads on this site, and in most cases one is left arguing with the wisdom seekers who don't necessarily want to move away from a module they've already invested in. Hence the recommendation against the module in general makes sense - it's one of those "only use this if you know what you're doing and why" things.

      XML::Rules is somewhat promising, but still adds a lot of extra complications.

      Really? I personally don't think so; I have several XML::Rules examples on my scratchpad.

      True, for that reason I do not use XML::Twig for small and simple files but prefer XML::Simple.
      So having a solution to simply get XML data and put it in a hashref is exactly why I ended up with XML::Simple.
      I did not yet have any problems with the parsing side of XML::Simple and did not realize the "PLEASE DO NOT USE THIS MODULE IN NEW CODE." part.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2021-10-19 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (77 votes). Check out past polls.

    Notices?