http://www.perlmonks.org?node_id=872988


in reply to Simpler than XML::Simple

The only solution for this type of problem is XML::Compile.

Why? Apparently the problem here is to get XML data serialized as perl data structures. I see two use cases: either the producer and the consumer of the XML data is the same system, or it is different systems, for example us and a different party.

In the first case I don't see why to go the XML path at all. It is much easier to code and probably much more efficient if just a data serialization format is used --- YAML, JSON, Storable, bencode, perl (Data::Dumper) or whatever. Typically this involves one line of code for serializing and deserializing, and should always be faster than doing some XML parsing.

In the second case there are two parties which need to handle the XML data. In this case, you must have an XML schema, to have a contract how the XML data should look like. And if you have the XML schema, then you can easily use XML::Compile to gain at least the simplicity of serializing and deserializing.

Replies are listed 'Best First'.
Re^2: Simpler than XML::Simple
by grantm (Parson) on Nov 22, 2010 at 21:16 UTC
    In the second case there are two parties which need to handle the XML data. In this case, you must have an XML schema

    Heh, good luck with that it in the real world :-) My real-world experience led me to postulate the law of The "Perl end" of XML.

      The [Perl side] inevitably has to bend over and take it.

      I'm furious with you, sir -- furious! -- for making so much pain seem so fscking funny.

        That's the price of being flexible.

      Aw, dang it! The link "Perl End" gives an error page. Got update?
Re^2: Simpler than XML::Simple
by Jenda (Abbot) on Nov 22, 2010 at 20:07 UTC

    "Must have an XML schema" ... get real! Yeah, you might have a schema. And the schema migh even be reasonable. Quite often it's not. Ever heard for example of HR-XML? What a ... massive overcomplicated schema. With each company using different parts of the schema. A mess.

    There is never "the only solution".

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

      Well, the real world ... my experience is that it's hard to get just well-formed and correctly encoded XML files from external parties.

      Did you know that the "trang" tool is capable of creating a schema out of sample data? So I don't see the advantage with using XML::Smart.

        I don't see the advantage with using XML::Smart either :-)

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