jenkins - Python: How do you use lxml to parse xml tags with periods? -


i attempting parse jenkin's job xml files using lxml module python. looks this:

<triggers>     <hudson.triggers.timertrigger>        <spec>h h(6-21)/3 * * *</spec> </hudson.triggers.timertrigger> 

i using lxml's handy objectify module, gets confused when try this:

root.triggers.hudson.triggers.timertrigger.spec = 'something' 

i attributeerror: no such child: hudson. of course there's no attribute named hudson! how 1 work goofy piece of xml this?

for additional context, here code:

from lxml import objectify import jenkins  j = jenkins.jenkins('http://local.jenkins.instance') xml = j.get_job_config('job_name') root = objectify.fromstring(xml) root.triggers.hudson.triggers.timertrigger.spec = 'something' 

it make sense triggers.hudson.triggers.timertrigger interpreted trying access <timertrigger> element in following structure, hence complained hudson child element not found when given op's actual xml :

<triggers>    <hudson>      <triggers>        <timertrigger>          <spec>h h(6-21)/3 * * *</spec>        </timertrigger>      </triggers>    </hudson>  </triggers> 

one possible way acess child element name contains dots without having switch etree using __getattr__() method :

>>> root.triggers.__getattr__('hudson.triggers.timertrigger').spec 'h h(6-21)/3 * * *' 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -