The XML file looks like this
<?xml version="1.0"?>
<application name="pos">
<artifact id="example.war" type="war" cycle="ReleaseX-Sprint1">
<jira>tick-1,tick-2,</jira>
<jenkins>http://localhost:0000/hudson</jenkins>
<kportal/>
<scm>
<transaction id="111" user="user1">
<file name="a/b/c/d.txt"/>
<file name="x/y/z.xml"/>
</transaction>
</scm>
</artifact>
</application>
I want to add a value to the kportal
node for a particular artifact node
so that it looks like <kportal>KPORTAL-1</kportal>
My code looks like this
my $manifestDoc = $manifestFileParser->parse_file($manifestFile);
my $xpathKportal = qq(//application[\@name="$applicationName"]/artifact[\@id="$artifactID"]/kportal);
my $newdeploymentNode = $manifestDoc->findnodes($xpathKportal);
$newdeploymentNode->removeChildNodes();
$newdeploymentNode->appendText('KPORTAL-1');
I am getting the error
Can't locate object method "removeChildNodes" via package "XML::LibXML::NodeList"
XML::LibXML::Node::findnodes
returns a NodeList
object in scalar context, but a list of nodes in list context. The NodeList
does not have a removeChildNodes
method. Suggested solution: Use a list on the left side of =
to force list context.
my ($new_deployment_node) = $manifest_doc->findnodes(...);