Subject: | map_xmlns bug |
Date: | Mon, 6 Aug 2012 15:58:33 +0000 |
To: | "'bug-XML-Twig [...] rt.cpan.org'" <bug-XML-Twig [...] rt.cpan.org> |
From: | "McBurnett, Roe D" <roe.mcburnett [...] ericsson.com> |
When using namespaces, it is allowed to identify an element as a particular type in an already defined namespace. the map_xmlns does not convert the namespace prefix for the types correctly.
The code:
#! /usr/bin/perl
use XML::Twig;
$x = XML::Twig->new(map_xmlns => {"http://namespace/CommandService" => "cmdsvc",
"http://namespace/ShelfService" => "shlsvc" }, pretty_print => "indented");
$x->parse('<ns1:list
xmlns:ns1="http://namespace/CommandService"
xmlns:ns2="http://namespace/ShelfService"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Show quoted text
>
<commands>
<commandId>1</commandId>
<command xsi:type="ns2:find" >
<equipmentFilter>...</equipmentFilter>
</command>
</commands>
<commands>
<commandId>2</commandId>
<command xsi:type="ns2:getByName" >
<name>...</name>
</command>
</commands>
</ns1:list>');
$x->print();
Generates the following:
<cmdsvc:list xmlns:cmdsvc="http://namespace/CommandService"
xmlns:shlsvc="http://namespace/ShelfService"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<commands>
<commandId>1</commandId>
<command xsi:type="ns2:find">
<equipmentFilter>...</equipmentFilter>
</command>
</commands>
<commands>
<commandId>2</commandId>
<command xsi:type="ns2:getByName">
<name>...</name>
</command>
</commands>
</cmdsvc:list>
It should generate this:
<cmdsvc:list
xmlns:cmdsvc="http://namespace/CommandService"
xmlns:shlsvc="http://namespace/ShelfService"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Show quoted text >
<commands>
<commandId>1</commandId>
<command xsi:type="shlsvc:find" >
<equipmentFilter>...</equipmentFilter>
</command>
</commands>
<commands>
<commandId>2</commandId>
<command xsi:type="shlsvc:getByName" >
<name>...</name>
</command>
</commands>
</cmdsvc:list>
This example was created using perl:
$ perl -v
This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int
(with 13 registered patches, see perl -V for more detail)
Copyright 1987-2009, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
and XML::Twig:
Show quoted textcpan> i XML::Twig
CPAN: Storable loaded ok (v2.30)
Reading '/home/cpan/Metadata'
Database was generated on Thu, 26 Jul 2012 15:58:03 GMT
CPAN: YAML loaded ok (v0.71)
Reading 54 yaml files from /home/cpan/build/
CPAN: Time::HiRes loaded ok (v1.9719)
..................................DONE
Restored the state of none (in 0.8281 secs)
Module id = XML::Twig
DESCRIPTION A module for easy processing of XML
CPAN_USERID MIROD (Michel Rodriguez <xmltwig@gmail.com>)
CPAN_VERSION 3.40
CPAN_FILE M/MI/MIROD/XML-Twig-3.40.tar.gz
UPLOAD_DATE 2012-05-10
DSLIP_STATUS RmpOp (released,mailing-list,perl,object-oriented,Standard-Perl)
MANPAGE XML::Twig - A perl module for processing huge XML documents in tree mode.
INST_FILE /usr/lib/perl5/site_perl/5.10/XML/Twig.pm
INST_VERSION 3.40
Show quoted textcpan>
-Roe McBurnett
Message body is not shown because it is too large.