How to not load the comments while parsing XML in lxml

前端 未结 1 361
情书的邮戳
情书的邮戳 2020-12-16 16:53

I try to parse XML file in Python using lxml like this:

objectify.parse(xmlPath, parserWithSchema)

but XML file may contains comments in st

相关标签:
1条回答
  • 2020-12-16 17:26

    Set remove_comments=True on the parser (documentation):

    from lxml import etree, objectify
    
    parser = etree.XMLParser(remove_comments=True)
    tree = objectify.parse(xmlPath, parser=parser)
    

    Or, using the makeparser() method:

    parser = objectify.makeparser(remove_comments=True)
    tree = objectify.parse(xmlPath, parser=parser)
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题