FAQ Database Discussion Community


How to get raw XML code from XML::Twig element

xml,perl,xml-twig
I'm a super-beginner with XML::Twig. I have an XML::Twig element with some HTML code in it. I can do $element->text And get the text from it, but it strips out all the HTML tags, making them children. Is there anyway to just get the full code from the element? I'm...

With XML::Twig, is there a way of find a 'first_child' with a particular attribute?

xml,perl,xml-twig
I've some XML that looks like this: <?xml version="1.0" encoding="UTF-8"?> <DataSet> <Category> <Name mode="source">somename</Name> <Name mode="destination">someothername</Name> <Content>Some text here</Content> </Category> </DataSet> What I'm trying to do is process the 'Category', and extract a different name based on the context. I've tried iterating it with children - this works: use strict;...

$twig->purge is giving empty file

perl,xml-twig
I may be asking a basic question but it's killing me. Following is my code snippet #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $twig = new XML::Twig( twig_handlers => { TRADE => \&TRADE } ); $twig->parsefile('1510.xml'); $twig->set_pretty_print('indented'); $twig->print_to_file('out.xml'); sub TRADE { my ( $twig, $TRADE ) = @_; #added...

Perl: Receive multiple children of XPath element

xml,perl,xpath,xml-twig
I am using XML::Twig to parse an XML file and print some info. Here is my XML File: <report> <reportheader> <month>February 2015</month> <dateofgeneration>20/02/2015 - 12:29:02</dateofgeneration> </reportheader> </report> and I have the following code: XML::Twig->new( twig_handlers => { '/report/reportheader' => sub { printf qq|%s\n|, $_->text; }, }, )->parsefile($ARGV[0]); Unfortunately this prints...

Assembling XML in Perl

xml,perl,xml-twig
I'm needing to make API calls to a NetApp filer. I know what raw XML I need to send: <? xml version="1.0" encoding="utf-8" ?> <!DOCTYPE netapp SYSTEM "file:/etc/netapp_filer.dtd"> <netapp version="1.7" vfiler="somevfiler" xmlns="http://www.netapp.com/filer/admin"> <nfs-exportfs-list-rules> <pathname>/vol/path/to/somewhere</pathname> </nfs-exportfs-list-rules> </netapp> Having started assembling as 'plain text', I've been trying to 'do it better' with...

Unable to get highest version of the TRADE in Perl

perl,xml-twig
I have just started learning Perl and got stuck in precarious scenario. Input Source XML FILE is: <STATEMENT> <TRADE origin = "BANK", ref="1",version="1"> <EVENT type="PRO"> <EVENTNAR key = "USE" val = "MY"/> <EVENTNAR key = "USEE" val = "MYY"/> </EVENT> </TRADE> <TRADE origin = "BANK", ref="1",version="2"> <EVENT type="PRO"> <EVENTNAR key...

Basic parsing of XML string with XML::Twig

xml,perl,xml-twig
I've used XML::Simple for over a decade and it's done everything I need it to, and I barely ever touch Perl any more. Though right now I need to parse an XML string to simply: get all of the elements that are children of the root, and for each get...

How to apply an IN clause in Perl by passing arguments from the command line

perl,xml-twig
I am new to Perl, and am trying to apply a filter condition on XML files using the XML::Twig module. Following is my code: #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $SOURCEFILE = $ARGV[0]; my $FILELOCATIONIN = $ARGV[1]; my $twig = new XML::Twig( twig_handlers => { 'STOCKEXT/STOCK' => \&STOCK...

Delete common XML tags from second XML file while merging two XML files

xml,perl,xml-twig
I am able to merge two XML file data with the help of XML::Twig module but in some cases there are chances of same tag appearing in both the XML files in such a situation I need to keep the data from first file intact and delete it from the...