Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HowTo - manipulating an existing tree 1

Status
Not open for further replies.

shlomyb

Programmer
Nov 14, 2006
32
IL
I use XML::DOM to get a xml to a tree.
By getChildern I can get a list of a specific node.

But how can I manipulte this tree by insert a new node / delete a node and so one...

thanks.
 
Code:
use Data::Dumper;
use XML::DOM;

my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("file.xml");

print Dumper($doc);
will show you what the structure looks like once it has been parsed. Once you know this, you can think about modifying it...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks , but is there an interface that I can use instead ?
(such as setNode() , etc...)


How can I transfer a tree to an XML ?

and again , thanks.
 
XML::DOM seems to have a method
Code:
$doc->printToFile ("out.xml");
that you can use to write it out again.

As for the other, you could always rtfm on CPAN. That's all I'm doing...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
rtfm = meaning searching ?
Cause I am doing it all day now but mybe because it is my first Perl day , I can not find any directions regarding the
" =is there an interface that I can use instead ?
(such as setNode() , etc...)" problem...

 
The node objects have an insertBefore and a replaceChild method you might be able to use.

If this is really your first exposure to perl, then parsing XML with XML::DOM is going to be a pretty steep learning curve.

rtfm : read the fine manual

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top