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
}
}
----------------------------------------------------------------------------
------------------------------
<!DOCTYPE harnessTaskList SYSTEM "harnessTaskList.dtd">
<harnessTaskList extensionClassname = "tools.update.TaskHarnessExtForUDT"
logCategory = "update/info">
<!-- Task UDT
Runs the update delivery tool
-->
<taskEntry uniqueName = "DiskSpace"
description = "Checks if the necessary space is
available on disk to proceed with update"
logCategory = "update/info"
canRerun = "true">
<javaTask className = "tools.update.DiskSpace"/>
</taskEntry>
<taskEntry uniqueName = "UDT"
description = "Runs the update delivery tool"
dependency = "DiskSpace"
logCategory = "update/info"
canRerun = "true">
<javaTask className = "tools.update.UpdateDeliveryTool"/>
</taskEntry>
<taskEntry uniqueName = "EnableLanguages"
description = "Install files for language pack."
dependency = "UDT"
canRerun = "true"
logCategory = "lpi/info">
<javaTask className =
"tool.update.languagepack.EnableLanguage"/>
</taskEntry>
<taskEntry uniqueName = "MergeConfig"
description = "Merges language related files to config."
dependency = "UDT, EnableLanguages"
logCategory = "lpi/info"
canRerun = "true">
<javaTask className = "tool.update.languagepack.MergeConfig">
<arg name="sample" value="false"/>
-------------- This is the value I am trying to change
</javaTask>
</taskEntry>
</harnessTaskList>