title: AssertionError: Unknown node type: 3 when encrypting SOAP body content with dm.xmlsec.binding
body: <p>I'm getting an error when I try to encrypt the body of a SOAP XML message using <a href="https://pypi.org/project/dm.xmlsec.binding/" rel="nofollow noreferrer">https://pypi.org/project/dm.xmlsec.binding/</a>. </p>
  
  <pre><code>Traceback (most recent call last):
    File "./manage.py", line 14, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/Users/romeroqj/.virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
      utility.execute()
    File "/Users/romeroqj/.virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/Users/romeroqj/.virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/Users/romeroqj/.virtualenv/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
      output = self.handle(*args, **options)
    File "/Users/romeroqj/Desktop/management/commands/encrypt.py", line 63, in handle
      encrypted_xml = enc_ctx.encryptXml(enc_data, doc.getroot())
    File "_xmlsec.pyx", line 555, in dm.xmlsec.binding._xmlsec.EncCtx.encryptXml (src/_xmlsec.c:7336)
    File "_xmlsec.pyx", line 637, in dm.xmlsec.binding._xmlsec.lxml_safe_dealloc (src/_xmlsec.c:8132)
    File "src/lxml/public-api.pxi", line 29, in lxml.etree.elementFactory
    File "src/lxml/etree.pyx", line 1607, in lxml.etree._elementFactory
    File "src/lxml/classlookup.pxi", line 403, in lxml.etree._parser_class_lookup
    File "src/lxml/nsclasses.pxi", line 174, in lxml.etree._find_nselement_class
    File "src/lxml/classlookup.pxi", line 257, in lxml.etree._callLookupFallback
    File "src/lxml/classlookup.pxi", line 336, in lxml.etree._lookupDefaultElementClass
  AssertionError: Unknown node type: 3
  </code></pre>
  
  <p>The error occurs when I try to encrypt the content of the body (xmlsec.TypeEncContent), but it works when I try to encrypt the body element (xmlsec.TypeEncElement). Here's the code:</p>
  
  <pre><code>import dm.xmlsec.binding as xmlsec
  from dm.xmlsec.binding.tmpl import EncData, fromstring
  
  key_mngr = xmlsec.KeysMngr()
  key = xmlsec.Key.load('cert.pem', xmlsec.KeyDataFormatCertPem)
  key.name = 'cert.pem'
  key_mngr.addKey(key)
  enc_data = EncData(
      xmlsec.TransformAes128Cbc, type=xmlsec.TypeEncContent
  )
  enc_data.ensureCipherValue()  # target for encryption result
  enc_ctx = xmlsec.EncCtx(key_mngr)
  enc_ctx.encKey = xmlsec.Key.generate(
      xmlsec.KeyDataAes, 192, xmlsec.KeyDataTypeSession
  )
  doc = fromstring(xml_data)
  body = doc.find('soap:Body', namespaces=NAMESPACES)  # NAMESPACES is redacted for brevity
  encrypted_xml = enc_ctx.encryptXml(enc_data, doc.getroot())
  </code></pre>
  
  <p>The XML data looks something like this:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soap:Header&gt;
      ...
      &lt;/soap:Header&gt;
      &lt;soap:Body Id="Body"&gt;
      ...
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>What could be wrong here?</p>
  
  <p>I'm not sure if this is relevant or related, but I tried to do the same using a different library <a href="https://github.com/mehcode/python-xmlsec/issues/83" rel="nofollow noreferrer">https://github.com/mehcode/python-xmlsec/issues/83</a> and I got a Segmentation fault error, however, it worked when I tried to encrypt the element. This pattern makes me believe there's something wrong in this approach.</p>
  
  <p>Any hints are appreciated. Thanks in advance!</p>