Here is a part of a jenkins xml file.
I want to extract the defaultValue of project_name
with xpath.
I this case the value is *****
.
<?xml version='1.0' encoding='UTF-8'?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>customer_name</name>
<description></description>
<defaultValue>my_customer</defaultValue>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>project_name</name>
<description></description>
<defaultValue>*****</defaultValue>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>
I use etree of python, but AFAIK this does not matter much since this is a xpath question.
My current xpath knowledge is limited. My current approach:
for name_tag in config.findall('.//name'):
if name_tag.text=='project_host':
default=name_tag.getparent().findall('defaultValue')[0].text
Here I get AttributeError: 'Element' object has no attribute 'getparent'
I thought about this again, and I think that looping in python is the wrong approach. This should be selectable via xpath.