Ravinder Arepally wrote:
All,
I am trying to parse a XML file and change an element value. Below is code of mine where I am doing this. However, setAttribute doesn't
work and it doesn't give any error message too.
I spent enough time and doesn't make sense to me. I get right value using
getAttribute('value).
XML file is also pasted at the end of this mail. Any help or pointer is
greatly appreciated. Any suggestions in writing better code for this task is also appreciated.
Thank you,
Ravi.
---------------------------------------------------
my $udtTaskFile =
"$depotLocation/updates/$udtBaseName/tasks/$udtBaseName"."_cs_udt.xml";
print ("udtTaskfile is : $udtTaskFile \n"); ------- XML file which is
pasted at end of this mail.
Util::safeCopy("$udtTaskFile", "$udtTaskFile".time()); -- I have Util.pm my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile($udtTaskFile);
my @taskList = $doc->getElementsByTagName('taskEntry');
foreach my $task (@taskList) {
if ($task->getAttribute('uniqueName') eq "MergeConfig"){
my $javaTask = $task->getElementsByTagName('javaTask');
if (! $javaTask) {
$log->write("ERROR: Couldn't find any Java tasks in
$udtTaskFile ");
return "Problem configuring installLPI. Couldn't find any Java
Tasks in $udtTaskFile. ";
}
my $innerTask = $javaTask->item(0)->getElementsByTagName('arg');
if (! $innerTask) {
$log->write("ERROR: Couldn't find any languagepack tasks in
$udtTaskFile ");
return "Problem configuring installLPI. Couldn't find any
languagepack Tasks in $udtTaskFile. ";
}
my $value = $innerTask->item(0)->getAttribute('value');
print ("value is 333333333333 $value \n"); -------- This prints
right value
$innerTask->item(0)->setAttribute('value', "true"); ----- This is not
working. No error and it doesn't change value
}
}

Please don't cross post, try one list then the other if the first doesn't provide acceptable resolution.


<snip sample file>

Does it not change the value of the internally represented structure, or in the file itself? Have you tried dumping the structure (not sure if it works with XML::DOM) using Data::Dumper? I am assuming it isn't throwing an exception about missing methods, I tried to track down where setAttribute is inherited from but the XML::DOM tree is a pretty big tangle.

Can you be more specific about precisely what isn't working?

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to