Skip Menu |

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

Report information
The Basics
Id: 51517
Status: new
Priority: 0/
Queue: XML-XPath

People
Owner: Nobody in particular
Requestors: work.serge [...] gmail.com
Cc:
AdminCc:

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



Subject: XML::XPath::Node::ElementImpl::new issue (attributes are not created)
Date: Sat, 14 Nov 2009 04:40:40 +0300
To: bug-XML-XPath [...] rt.cpan.org
From: Serge Vinogradov <work.serge [...] gmail.com>
Hi, guys! I'm trying to create the following XML by XPath: my $xmlTree = XML::XPath->new(xml => '<a></a>'); $xmlTree->createNode( '/a/b/item[@type = \'A\'][1]/subitem[@name = \'QQQ\']/@value'); my $d = $xmlTree->find('/a'); my $xml = XML::XPath::XMLParser::as_string(($d->get_nodelist)[0]); $xml =~ s/></>\n</g; $xml =~ s/"/'/g; print "$xml\n"; expected XML: <a> <b> <item type='A' id='1'> <subitem name='QQQ' value='' /> </item> </b> </a> resulted XML: <a> <b> <item[((attribute::type) = ('A'))][(1)]> <subitem[((attribute::name) = ('QQQ'))] value='' /> </item[((attribute::type) = ('A'))][(1)]> </b> </a> During the debug I found the issue in func XML::XPath::Node::ElementImpl::new(/usr/lib/perl5/vendor_perl/5.8.8/XML/XPath/Node/Element.pm:23) It gets name 'subitem[((attribute::name) = (\'QQQ\'))]' and doesn't try to create attributes out of it. The only way to fix the issue I found so far is to create all missing tags before calling the desired function: $xmlTree->createNode( '/a/b/item/@type'); $xmlTree->setNodeText( '/a/b/item/@type', 'A'); $xmlTree->createNode( '/a/b/item[@type = \'A\']/@id'); $xmlTree->setNodeText( '/a/b/item[@type = \'A\']/@id', '1'); $xmlTree->createNode( '/a/b/item[@type = \'A\']/subitem/@name'); $xmlTree->setNodeText( '/a/b/item[@type = \'A\']/subitem/@name', 'QQQ'); $xmlTree->createNode( '/a/b/item[@type = \'A\']/subitem[@name = \'QQQ\']/@value'); $xmlTree->setNodeText( '/a/b/item[@type = \'A\']/subitem[@name = \'QQQ\']/@value', 888); But it has it's limitations (with "[1]" part) & complexity. Can you please help with this issue? Thanks. -- Serge Vinogradov work.serge@gmail.com ICQ: 269813255