Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Can you please tell me why parsing the following XML returns an incomplete value?
<xml> <cat> <email_address><![CDATA[foo@yahoo.com]]></email_address> <name>foo</name> </cat> </xml>
I use the following code to get the value of email_address and it returns foo.com instead of foo@yahoo.com.
my $obj = XML::Twig->new(twig_roots =>{'cat' => \&pp}); $obj->parse($sz); sub pp { my($objXML, $objTag) = @_; $grhshXML = {}; @garTags = (); @garTags = $objTag->children(); foreach my $arTag (@garTags) { $grhshXML->{$arTag->gi()} =$arTag->text(); } }
I also tried checking "$arTag->is_cdata" but it returns no value at all. Can you please help? Thanks

Replies are listed 'Best First'.
Re: parsing CDATA with XML Twig
by Cody Pendant (Prior) on Nov 26, 2005 at 02:08 UTC
    The most obvious answer must be "because your string is being interpolated". The "@yahoo" part is being interpreted as an array, which is undefined. If you "use strict" it will confirm this.


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print