in reply to XML::LibXML - WHAR HASH TREES WHAR?!

Ignoring your attempts at using an XML parser as an XML generator, one is left with:

# XML::Smart print $sXML->{book}[3]{title}; # XML::LibXML print $root->find('book[4]/title');
# XML::Smart my @books = $sXML->{book}('@'); # XML::LibXML my @books = $root->findnodes('book');

So XML::LibXML is a little bit wordier, but there's a good reason for that. XML::Smart chose to sacrifice some critical functionality to offer its interface.

Either of the first three would make XML::Smart incapable of dealing with the most commonly used XML format (XHTML). The second means it's incapable of handling just about every XML format out there.

Update: Simplified an XML::Smart example that wasn't optimal.
Update: Added third and fourth bullet.

Replies are listed 'Best First'.
Re^2: XML::LibXML - WHAR HASH TREES WHAR?!
by SineSwiper (Beadle) on Jul 15, 2011 at 19:18 UTC

    Ignoring your attempts at using an XML parser as an XML generator

    Who said LibXML is just a parser?

    XML::LibXML supports namespaces. XML::Smart doesn't (except when used to generate documents).

    Yes, probably because it's too old for it. It doesn't support XSD, either, which is part of the reason I'm switching to LibXML.

    I'm not debating that Smart is missing critical functionality. I'm frustrated that LibXML is this mature, and is a Perl module, and yet is this clunky at navigation. Nor are there any modules for XML::LibXML that enhance it to fix its navigation.

    I mean seriously, this is what I have to do to check for a tag and fill data for it:

    # Before $sn->{'SourceDBType'} ||= 'XML'; # After $sn->findvalue('SourceDBType') || ($sn->find('SourceDBType') ? $sn->fi +nd('SourceDBType')->setData('XML') : $sn->addNewChild(undef, 'SourceD +BType')->setData('XML'));

    Are you kidding me?!?!  That's a horrible mess!  And god forbid I do something like $sn->find('SourceDBType')->setData('XML') without checking the existence of SourceDBType first.  That'll give me a fatal error.

    XML::LibXML preserves the order of the children of elements. XML::Smart can't even list the children of an element.

    Incorrect. Smart does both: $XML->{server}{address}[1]('@');  # there's your children of that <address> tag

      Who said LibXML is just a parser?

      You, for one.

      Yes, probably because it's too old for it.

      I meant it can't support namespaces.

      I'm not debating that Smart is missing critical functionality.

      Neither was I. I was referring to what its design allows.

      Are you kidding me?!?! That's a horrible mess!

      Are you kidding me? The equivalent would be

      $sb->setAttribute(SourceDBType => 'XML') if !$sb->setAttribute('XML');

      Incorrect. Smart does both:

      Sorry, but that's not working.

      use strict; use warnings; use feature qw( say ); use XML::Smart qw( ); my $doc = XML::Smart->new(<<'__EOI__'); <root> <node> a <foo/> b <bar/> c </node> </root> __EOI__ my @children = $doc->{root}{node}[0]('@'); say @children == 5 ? "ok" : "XXX";
      1 XXX

        Neither was I. I was referring to what its design allows.

        All the more reason to allow both methods.

        Are you kidding me? The equivalent would be

        $sb->setAttribute('XML') if !$sb->setAttribute('XML');

        Okay, what if it's a node and not an attribute?

        Sorry, but that's not working.

        Sorry, my bad; it should be hash:

        my %children = $doc->{root}{node}[0]('%'); say join "\n", map { "$_ = $children{$_}" } keys %children; say keys %children == 6 ? "ok" : "XXX"; # includes extra "CONTENT" ke +y/value