Skip Menu |

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

Report information
The Basics
Id: 66830
Status: resolved
Priority: 0/
Queue: XML-XML2JSON

People
Owner: Nobody in particular
Requestors: rutgeraldo@gmail.com (no email address)
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.05
Fixed in: (no value)



Subject: xmlns declarations and root attributes
The code doesn't parse xmlns declarations in 0.05. The attached patch fixes that by converting them to properties the same way it treats attributes (i.e. normally with the @ prefix). Also, when reading xml with a processing instruction at the top, e.g. <?xml version="1.0" encoding="UTF-8"?>, the version and encoding are added as attributes *before* to the root element in the root object, but when reading json, those @version and @encoding keys aren't recognized as a processing instruction. Instead, the code tries to instantiate an element with the name "@version", which fails. The workaround for now is to strip all the attributes from the root object. This works because it is the parent of the root element, so any attributes on the root element are untouched.
Subject: XML2JSON.diff
357,368d356 < my @Namespaces = $Root->getNamespaces(); < if (@Namespaces) < { < foreach my $Ns (@Namespaces) < { < my $Prefix = $Ns->declaredPrefix; < my $URI = $Ns->declaredURI; < $Prefix = ":$Prefix" if $Prefix; < $Obj->{ $Self->{attribute_prefix} . 'xmlns' . $Prefix } = $URI; < warn "xmlns$Prefix=\"$URI\"" if $Self->{debug}; < } < } 490,501d477 < my @Namespaces = $Child->getNamespaces(); < if (@Namespaces) < { < foreach my $Ns (@Namespaces) < { < my $Prefix = $Ns->declaredPrefix; < my $URI = $Ns->declaredURI; < $Prefix = ":$Prefix" if $Prefix; < $ElementHash->{ $Self->{attribute_prefix} . 'xmlns' . $Prefix } = $URI; < warn "xmlns$Prefix=\"$URI\"" if $Self->{debug}; < } < } 721d696 < delete @$Obj{ grep { /^$Self->{attribute_prefix}/ } keys %$Obj }; 750c725 < { --- > { 755,759c730 < my $Root; < eval { $Root = $Dom->createElement($Name) }; < if ( $@ ) { < die "Problem creating root element $Name: $@"; < } --- > my $Root = $Dom->createElement($Name);
I have applied your patch and uploaded it as 0.06. I did comment out this line from your patch though: delete @$Obj{ grep { /^$Self->{attribute_prefix}/ } keys %$Obj }; If you send me some example XML that the above code was meant for I will likely add it in the next version. (Sorry its been so long between versions!)