So far, I haven't been able to extract the xml:lang attribute using XML::Parser. It seems to ignore attributes with the xml: prefix.
My experience doesn't match yours. I can clearly see the attribute 'xml:lang' in the list of attributes.
use XML::Parser; use Data::Dumper; my $parser = XML::Parser->new(Handlers => { Start => sub { print Dumper [ @_[1 .. $#_] ] } } ); $parser->parse(\*DATA); __DATA__ <FILE> <FOO xml:lang="en"> <BAR/> </FOO> <FOO xml:lang="ru"> <BAR/> </FOO> </FILE>
Result:
$VAR1 = [ 'FILE' ]; $VAR1 = [ 'FOO', 'xml:lang', 'en' ]; $VAR1 = [ 'BAR' ]; $VAR1 = [ 'FOO', 'xml:lang', 'ru' ]; $VAR1 = [ 'BAR' ];
Anyway: you might be interested in using a parser that can handle XPath, as it might make filtering out just the contents you want, just a little bit easier.

Although personally, I think XML::Parser is fine... :)


In reply to Re: Parsing xml:lang attribute by bart
in thread Parsing xml:lang attribute by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.