Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm in the process of using WxPerl to build an app in conjunction with XRC to drive the UI. Is it possible to compress the XMLs files so users are unable to alter the contents since the two are so tightly integrated?

A google search turned up this module from chilkatsoft but they don't offer a free API to do XML compression.

Any thoughts

Replies are listed 'Best First'.
Re: XML compression?
by CountZero (Bishop) on Nov 11, 2008 at 19:38 UTC
    You don't need compression, you need encryption or a digest if you want the users not to alter the contents. The easiest solution is to calculate a Digest over your XML file and store the digest into the main app. It then checks the digest of the XML file and if it does not match, refuses to run. Any change to the XML will change the digest and the user would have to recalculate the digest and add it to the main app to make it work again. That will stop if not J. Random Hacker then certainly Fred Foobar from messing with the XML file.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      So basically if I create a digest based on the current XML file and a user alters it in some way I can raise a flag.

      You wouldn't have any examples of this would you? :)

      Thanks

        It is as easy as:
        use strict; use Digest::file qw(digest_file_hex); die 'XML file has been changed!\n' unless digest_file_hex( 'test.xml', "MD5" ) eq 'e253b427caacb6f0781f337a90658c6a'; print "Continue\n";

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: XML compression?
by jeffa (Bishop) on Nov 11, 2008 at 19:12 UTC

    Since XML is just text -- why not search for text compression? But to answer your question -- yes this seems very possible. But is it practical? What I don't understand, however, is why you give the users the ability to alter the contents in the first place. My solution would be to prevent them from having access to the files.

    But search CPAN and see if one of the many archiving and compression modules suites your needs. Feel free to ask specific questions about which ever module you pick if you run into troubles (installing, using, etc.).

    UPDATE: I like CountZero's suggestion. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Thanks jeffa,

      I don't intentionally give users access but I'm afraid of the curious person poking at the install directory :)

      You make a good point...I'm on a win32 box so I'm not sure how to restrict users from altering the files if they do find them.