How to add a namespace to an attribute in lxml

前端 未结 2 1458
别跟我提以往
别跟我提以往 2021-01-04 03:15

I\'m trying to create an xml entry that looks like this using python and lxml:


<
2条回答
  •  半阙折子戏
    2021-01-04 04:06

    Try this:

    builder = ElementMaker(namespace="http://a.different.url/blah/v.10",
                           nsmap={
                             'adlcp': "http://a.namespace.url/blah/v.10",
                             'anotherns': "http://a.different.url/blah/v.10"
                           })
    
    builder.resource()
    builder.attrib['href'] = "Unit 4.html"
    builder.attrib['{http://a.namespace.url/blah/v.10}scormtype'] = 'sco'
    
    print(etree.tostring(builder, pretty_print=True))
    

提交回复
热议问题