Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Not sure of any other XPath-on-streams freaks, let me know of any.

    Will take a look at that toolkit when next I dive in to EventPath implementation (see XML::Filter::Dispatcher [cpan.org] for that, those of you interested in streaming XPath implementations).

    Thanks for the pointer.

    - Barrie

    • Hand raised, waving frantically

      It has been in my todo list for ever... maybe between ripping the XPAth grammar from XML::Filter::Dispatcher and this I can write something really cool for XML::Twig.

      I'd bet on you getting there first though ;--(

      --
      mirod
      • Couldn't you go at it the lazy way and build that Twig functionality layered over XFD?

        --

        -- Robin Berjon [berjon.com]

        • by barries (2159) on 2003.01.29 11:41 (#16497)
          Here's how X::F::D does its pale immitation of TWIG-like things:
             '/*/b' => [ 'hash()'   => sub { use BFD; d xvalue } ],
             '/*/c' => [ 'struct()' => sub { use BFD; d xvalue } ],

          Those two will print out hashes (returned by xvalue()) for each <b> and <c> in the root element. Mind you, this isn't meant to look pretty or replace XML::TWIG, it's meant to provide limited TWIG-like functionality in the X::F::D environment so you can conveniently slurp a twig in to a HASH or HASH of HASHes (respectively) when doing other things with X::F::D.

          The first, hash() is a HASH reference of scalar strings (for attrs) and ARRAYs (for descendant elements) keyed with xpath-like expressions ('@attr' => $string, 'c/d' => [ @strings ]).

          The second, struct(), provides a nested structure of HASHes keyed somewhat like the first, but without flattening the structure in to a single hash:

          <root
              xmlns="default-ns"
              xmlns:foo="foo-ns"
              a="A"
              foo:a="FOOA"
          >
              <a aa1="AA1" foo:aa1="AA2">
                  <b>B1</b>
                  <foo:b>B2</foo:b>
              </a>
          </root>

          becomes (deleted a few strings to duck the overly oppressive use.perl lameness filter that seems to want to prevent people from talking about perl on use.perl. Oddly, adding more plain text triggers the wonky filter agian. Sigh.):

          $VAR1 = {
              'a' => [
                  {
                      '@aa2' => 'AA2',
                      'b' => [
                          {
                              '' => 'B1'
                          },
                          {
                              '' => 'B2'
                          }
                       ],
                       '@aa1' => 'AA1'
                   }
               ],
               '@a' => 'A'
          };

          And, Michel, please feel free to copy the grammar. I got it from an old James Clark posting and converted it from yacc to Parse::Yapp and added some EventPath things like start:: and end:: axes, etc.

          - Barrie