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


in reply to Struggling with XML

Hello.

With XML::Twig, maybe something like this. Twig has nice tutorial.

use strict;use warnings; use XML::Twig; my $t=XML::Twig->new( twig_roots => { '/root/dict[@key="data"]/list/dict' => sub { my ($twig,$elt)=@_; printf "%s = %s\n", $elt->att("key"), $elt->first_child_te +xt; }, }, )->parsefile('your.xml');

Replies are listed 'Best First'.
Re^2: Struggling with XML
by agentorange (Sexton) on Oct 05, 2012 at 13:28 UTC
    Looks like my login timed out whilst posting original. Thanks for responses. As I say I'm very new to Perl, ie. a couple of days, and not sure I fully understand the first response and cannot get XML::Twig to compile.
    Writing Makefile for XML::Twig malformed JSON string, neither array, object, number, string or atom, +at character offset 0 (before "(end of string)") at Makefile.PL line +147
    Therefore ideally a solution with XML::Simple or XML::LibXML would be preferable if possible. I think I'm close with the existing code just maybe not quite understanding something.