Questions tagged [xml-twig]

XML::Twig is a Perl module that provides easy and efficient processing of XML documents of all sizes.

In particular, it tries to avoid loading an entire XML document into memory at once so it can be used with huge files.

Resources

212 questions
4
votes
1 answer

How to remove comments from XML using Twig module

I'm using XML::Twig module to remove all the comments from an XML file. The sample file can be - node A content 1
4
votes
2 answers

Fixing of an XPath predicate for use in XML::Twig

I'm trying to write a subroutine in Perl that will delete a given node in XML when provided with the text values of some of the children nodes. Given XML like: ValA
Dave
  • 6,141
  • 2
  • 38
  • 65
4
votes
2 answers

Inefficient use of memory processing large file with Perl XML::Twig handlers

I occasionally need to extract data from a large XML database export. The file size is between 600 and 700 MBs. With a few days of research I concluded that XML::Twig is the way to go, because its handlers allow me to process the file…
Keve
  • 383
  • 2
  • 13
4
votes
3 answers

How can I add entity declarations via XML::Twig programmatically?

For the life of me I cannot understand the XML::Twig documentation for entity handling. I've got some XML I'm generating with HTML::Tidy. The call is as follows: my $tidy = HTML::Tidy->new({ 'indent' => 1, 'break-before-br' => 1, …
Sir Robert
  • 4,686
  • 7
  • 41
  • 57
4
votes
1 answer

Printing content of XML in Twig

I am trying to print some basic logs in Perl but I get stuck on a very simple issue: I cannot print the contents of XML tags. my $twig=XML::Twig->new(pretty_print => "nice"); $twig->parse($xml); my $root = $twig->root; my…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
4
votes
1 answer

How do I get the entire inner content of an XML node including element tags?

Using XML::Twig, is there a way to get the entire HTML of a node? I do not want the text of the node, but the entire HTML with tags and all. input XML

blah blah bla bla

line 2 test Code my…

Desai
  • 187
  • 2
  • 12
4
votes
2 answers

XML::Twig - set_text without clobbering structure

With XML::Twig using the set_text method - there is a warning: set_text ($string) Set the text for the element: if the element is a PCDATA, just set its text, otherwise cut all the children of the element and create a single PCDATA child for it,…
Sobrique
  • 52,974
  • 7
  • 60
  • 101
4
votes
1 answer

$twig->purge is giving empty file

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 }…
karan arora
  • 176
  • 9
4
votes
1 answer

Parallel processing of XML files

Currently, I have an application which is using XML::Twig and parses 20 XML files. Each file amounts to 0.5GB and the processing is done in a sequential manner: foreach (@files) { my $ti = XML::Twig->new( keep_encoding => 1, …
smith
  • 3,232
  • 26
  • 55
4
votes
1 answer

How Does XML::Twig keep_encoding work?

Ages ago, I found some Perl online which neatly formatted valid XML (tabs and newlines) when it was a single-line. The code is below. It uses XML::Twig to do that. It creates the XML::Twig object without keep_encoding ($twig = XML::Twig->new()) but…
matt freake
  • 4,877
  • 4
  • 27
  • 56
4
votes
4 answers

XPath variables in XML::Twig or Other

I'm using XML::Twig::XPath to work with ITS data, and am trying to figure out how to resolve XPath expressions with variables in them. Here's an example of what I need to work with from the ITS spec:
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
4
votes
1 answer

Perl XML::Twig - preserving quotes in and around attributes

I'm selectively fixing some elements and attributes. Unfortunately, our input files contain both single- and double-quoted attribute values. Also, some attribute values contain quotes (within a value). Using XML::Twig, I cannot see out how to…
ALF
  • 85
  • 4
4
votes
2 answers

How can I extract some XML data from a URL using XML::Twig?

I want to get a specific string, for example 123 in 123 from some XML that will be retrieved from a URL. I have write a code but stuck with an error message: Attempt to bless into a reference at /usr/share/perl5/XML/Twig.pm…
conandor
  • 3,637
  • 6
  • 29
  • 36
4
votes
4 answers

how to get the most deeply nested element nodes using xpath? (implementation with XMLTWIG)

I need to extract (XSLT, xpath, xquery... Preferably xpath) the most deeply nested element nodes with method (DEST id="RUSSIA" method="delete"/>) and his direct ancestor (SOURCE id="AFRICA" method="modify">). I don't want to get the top nodes with…
laurentngu
  • 357
  • 2
  • 13
1
2
3
14 15