Skip Menu |
 

This queue is for tickets about the XML-Rabbit CPAN distribution.

Report information
The Basics
Id: 71815
Status: resolved
Priority: 0/
Queue: XML-Rabbit

People
Owner: ROBINS [...] cpan.org
Requestors: jeffery.m.thompson [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.1.0
Fixed in: (no value)



Subject: Hashes with empty values
Download (untitled) / with headers
text/plain 1.3k
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?
Subject: Optional elements in XML throws exception when used with value_map
Download (untitled) / with headers
text/plain 1.8k
On Thu Oct 20 17:35:38 2011, Jeffery.M.Thompson wrote: Show quoted text
> > 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), Show quoted text
> ..., called at generated method (unknown origin) line 1 > > 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?
I was aware that optional attributes can cause problems, and I have been contemplating what would be the correct approach with them. I'm not entirely sure what is the best solution, to let them end up as undef (with a Maybe type constraint) or an empty string either in the _value, _map or _list constructs. I'm leaning towards an empty string, but then you'd have that situation where a missing attribute should be handled different from an empty attribute. Not sure how popular it is to devise XML formats that use this kind of logic. Do you have any experience with this? What would be really awesome is if you can create a minimal test case together with an example XML file that dies when you try it out.
Download (untitled) / with headers
text/plain 599b
I've fixed the problem in this commit: https://github.com/robinsmidsrod/XML-Rabbit/commit/529fab42e2021cacecb08d7489445542f4d96531 Please verify that it indeed solves your problem. There was a bug where I actually checked the value of the result of the xpath_value query instead of the xpath_key query when rejecting an element for the hash because of missing key. I've added a test case for both has_xpath_value_map and has_xpath_object_map. I've also fixed an unnecessary exception when the xpath_key query returns an empty result. Now I just skip the element instead of throwing an exception.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.