Python3 lxml builder
Question: I'm trying to create XML-file with python lxml builder lke below:

    
    
    <entityset>
      <entity>
        <temp code="1stCode"/>
          <attr code="2ndCode">
            <value>PythonIsFun</value>
          </attr>
          <attr code="3rdCode">
            <value>PythonIsStillFun</value>
          </attr>
      </entity>
    </entityset>
    

My attempt:

    
    
    import lxml.builder as lb
    
    def generate_xml(temp_code, value, value2):
    
        temp = lb.E.entityset(
            lb.E.entity(
                lb.E.temp(code='{0}'.format(temp_code)),
                lb.E.attr(code='2ndCode'),
                lb.E.value('{0}'.format(value)),
                lb.E.attr(code='3rdCode'),
                lb.E.value('{0}'.format(value2))
            )
        )
        print(etree.tounicode(temp, pretty_print=True))
    
    generate_xml('1stCode', 'PythonIsFun', 'PythonIsStillFun')
    

Output:

    
    
    <entityset>
      <entity>
        <temp code="1stCode"/>
        <attr code="2ndCode"/>
        <value>PythonIsFun</value>
        <attr code="3rdCode"/>
        <value>PythonIsStillFun</value>
        <attribute/>
      </entity>
    </entityset>
    

Problem is that I don't know how to add `<value> </value>` elements between
`<attr code="code here"> </attr>` tags. Is there a way to do it with lxml
element builder?


Answer: Just move `lb.E.value()` to be parameter of `lb.E.attr()` :

    
    
    temp = lb.E.entityset(
            lb.E.entity(
                lb.E.temp(code='{0}'.format(temp_code)),
                lb.E.attr(lb.E.value('{0}'.format(value)), code='2ndCode'),
                lb.E.attr(lb.E.value('{0}'.format(value2)), code='3rdCode'),
            )
        )
    

