Subject: | Hashes with empty values |
Module id = XML::Rabbit
CPAN_VERSION 0.001000
UPLOAD DATE 2011-09-27
INST_VERSION 0.1.0
perl v5.8.8 for x86_64-linux-thread-multi
Linux zoom 2.6.18-274.3.1.el5.centos.plus #1 SMP Wed Sep 7 05:38:58 EDT
2011 x86_64 x86_64 x86_64 GNU/Linux
When using
has_xpath_value_map 'element' => './namespace:element',
'.' => './@attribute';
On an element with an optional attribute it fails with the following error.
xpath_key value is empty, please revise your xpath_query at .....
XML::Rabbit::Trait::XpathValueMap::__ANON__(...
XML::Rabbit::Trait::XPath::__ANON__(...
Class::MOP::MIxing::AttributeCore::default('Class::MOP::Class::__ANON__::SERIAL::7=HASH(0x20894c0),
..., called at generated method (unknown origin) line 1
The ... are reference to the my code locations.
So I have in the xml
<element attribute = "here">With attribute</element>
<element>Without attribute</element>
To fix this so I could have a hash keyed on the element contents with
the attribute as a value I did the following
has_xpath_value_map 'element' => './namespace:element',
'.' => 'concat(./@type, count(./@type))';
This allows me to store a zero in the hash value which I can test
against for existence. I was wondering should the map function include
the ability to have a default value for the mapping to handle these
situations where the xpath would not return a value?