0
lxml.sax
을 사용하여 XML 문서를 수정하고 있으며 사용자 지정 속성을 startElementNS
메서드에 전달하고 싶습니다.lxml.sax 인터페이스를 통해 사용자 정의 속성을 전달하는 방법은 무엇입니까?
from lxml import sax
class MyContentHandler(sax.ElementTreeContentHandler):
def startElementNS(self, ns_name, qname, attributes):
if qname == 'text':
# the troublesome line
super().startElementNS((None, 'div'), 'div', {'class':'page'})
super().startElementNS(ns_name, qname, attributes)
그러나, documentation 음과 같이 attributes
매개 변수가 Attributes
객체가 아닌 일반 사전 있어야합니다 : 내 초기 코드는 이것이다. 디버깅을 통해 정확한 유형이 sax.xmlreader.AttributesNSImpl
인 것으로 밝혀졌지만이 클래스는 공식적으로 문서화되지 않았으므로 직접 인스턴스화 할 수 없습니다.
startElementNS
방법에 본인의 특성을 제공하는 데 공식적이거나 해킹 된 방법이 있습니까? 시행 착오의