getValue from an XML having same attributes using Perl XMLDOM parser -
i trying value of 'taxamount' below xml contains same tag name @ different places.
from below xml, want value of 'taxamount' '7.2' under tag 'order', i'm getting 'taxamount' '1.2' under tag 'orderitem' in 'orderitemlist'.
could 1 me on getting value of 'taxamount' '7.2'?
i tried many things other similar questions, not succeeded in any.
<order> <customerid /> <iscustomercompany>false</iscustomercompany> <ordertimezone /> <orderdescription /> <orderitemlist> <orderitem> <orderitemid>1234</orderitemid> <itemcode /> <taxamount>6.0</taxamount> </orderitem> <orderitem> <orderitemid>1245</orderitemid> <itemcode /> <taxamount>1.2</taxamount> </orderitem> </orderitemlist> <currency>usd</currency> <amount>120</amount> <taxamount>7.2</taxamount> </order> the piece of code i'm using is,
use xml::dom; $xml = xml::dom::parser->new->parse( $self->fullresponse )->getdocumentelement; $order_tag = $xml->tag('order'); $tax_amount = $order_tag->getvalue('taxamount'); any appreciated.
can't specific module you're using, trick:
#!/usr/bin/perl use strict; use warnings; use xml::twig; $twig = xml::twig -> new ( ) -> parse ( 'your_xml_file' ); print $twig -> root -> get_xpath ( "./taxamount",0 ) -> text; note in example, "root" node order looking order beneath what's tripping up.
Comments
Post a Comment