Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: XML::DOM - NOT_FOUND_ERR

by Jenda (Abbot)
on Oct 23, 2008 at 23:32 UTC ( [id://719200]=note: print w/replies, xml ) Need Help??


in reply to Re^2: XML::DOM - NOT_FOUND_ERR
in thread XML::DOM - NOT_FOUND_ERR

The problem is that XML::DOM is a maze of objects. And each node object can only have one parent. So you first stick the <record> object in place of the first Thammasat and then MOVE the object in place of the second. You'd have to create a brand new $ritem each time you want to replace the original.

To tell the truth, you'd most likely do better if you dumped the module and used a different. I'm surprised mirod did not already suggest his XML::Twig, anyway I'll suggest my XML::Rules:

use strict; use XML::Rules; my $link = "Thammasat"; my $rlinks = { "institute" => ["test"], "year" => ["test"], "degree" => ["test"], "faculty" => ["test"], "major" => ["test"], "gpa" => ["test"], }; my $parser = XML::Rules->new( style => 'filter', ident => ' ', rules => { _default => 'raw extended', record => sub { return $_[0] => $_[1] unless $_[1]->{':institute'}{_conten +t} eq $link; return $_[0] => $rlinks; } }, ); $parser->filterfile('employee.xml', 'employee-filtered.xml');

The additional advantage is that this scripts doesn't load the whole file into memory, it parses the file, copies everything outside the <record> tag and only ever remembers that single tag with contents.

Replies are listed 'Best First'.
Re^4: XML::DOM - NOT_FOUND_ERR
by sureerat (Acolyte) on Oct 24, 2008 at 16:56 UTC
    Thank you Jenda for your guideline. I can fix the problem now using XML::DOM. I'm being interested in XML::Twig and your XML::Rules, I will study both and decide again what is the best for my project. You help me a lot. Thanks again ^_^

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://719200]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-03-28 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found