Skip Menu |

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

Report information
The Basics
Id: 74121
Status: open
Priority: 0/
Queue: XML-Hash-LX

People
Owner: Nobody in particular
Requestors: BBYRD [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.0603
Fixed in: (no value)



Subject: hash2xml needs a "convert to LibXML::Element" option
In need of a hash conversion to a element fragment, not a full document. Can a third option for hash2xml include the ability to hand out a XML::LibXML::Element object, instead of a full-blown Document?
Quick patch: *** LX.pm.old 2012-01-18 11:24:23.000000000 -0500 --- LX.pm 2012-01-18 11:34:59.000000000 -0500 *************** *** 101,109 **** XML could be L<XML::LibXML::Document>, L<XML::LibXML::DocumentPart> or string ! =head2 hash2xml $hash, [ doc => 1, ] [ OPTIONS ] ! Id C<doc> option is true, then returned value is L<XML::LibXML::Document>, not string =head1 OPTIONS --- 101,109 ---- XML could be L<XML::LibXML::Document>, L<XML::LibXML::DocumentPart> or string ! =head2 hash2xml $hash, [ return => 'd'|'e'|'s', ] [ OPTIONS ] ! If C<return> option is 'd', then returned value is L<XML::LibXML::Document>. If 'e', then the value is an L<XML::LibXML::Element>. Otherwise, a string is returned. (The C<doc =E<gt> 1> option is still supported for backwards-compatibility.) =head1 OPTIONS *************** *** 508,514 **** #warn "hash2xml(@_) from @{[ (caller)[1,2] ]}"; my $hash = shift; my %opts = @_; ! my $str = delete $opts{doc} ? 0 : 1; my $encoding = delete $opts{encoding} || delete $opts{enc} || 'utf-8'; my $doc = XML::LibXML::Document->new('1.0', $encoding); local @H2X{keys %opts} = values %opts if @_; --- 508,515 ---- #warn "hash2xml(@_) from @{[ (caller)[1,2] ]}"; my $hash = shift; my %opts = @_; ! my $return = lc delete $opts{return}; ! $return //= delete $opts{doc} ? 'd' : 's'; my $encoding = delete $opts{encoding} || delete $opts{enc} || 'utf-8'; my $doc = XML::LibXML::Document->new('1.0', $encoding); local @H2X{keys %opts} = values %opts if @_; *************** *** 516,523 **** #use Data::Dumper; #warn Dumper \%H2X; my $root = _h2x($hash); $doc->setDocumentElement($root); ! return $str ? $doc->toString : $doc; } =head1 BUGS --- 517,525 ---- #use Data::Dumper; #warn Dumper \%H2X; my $root = _h2x($hash); + return $root if ($return eq 'e'); $doc->setDocumentElement($root); ! return $return eq 'd' ? $doc : $doc->toString; } =head1 BUGS