Please bottom post....

Ravinder Arepally wrote:


I need to change value in file itself. It is not doing that. I am thinking setAttribute should change value of element in file. But my
below code is not doing that even though I am using same. My intention is to change value of <javaTask className = "tool.update.languagepack.MergeConfig">
<arg name="sample" value="false"/>


to

   <javaTask className = "tool.update.languagepack.MergeConfig">
                <arg name="sample" value="true"/>



Are you calling 'printToFile' or one of the other output methods, on an opened handle? I don't believe (though I suppose it is possible) that the parser is acting on the file directly. I suspect the in memory structure has been updated but you need to write it back out.


http://danconia.org




-----Original Message-----
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] Sent: Monday, June 07, 2004 8:09 PM
To: Ravinder Arepally
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: XML::DOM::Parser question !


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