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);