I'm trying to work through this answer in the QGIS (2.14) Python console to understand, ultimately, how to iterate over layers and print them with a template.

When I run the following code block.

I get a NameError that QDomDocument() is undefined.

myComposition = QgsComposition(myMapRenderer)
myFile = os.path.join(os.path.dirname(__file__), 'MMR_Template.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myDocument = QDomDocument()

Possibly related (can split into a separate question) I also get the warning DeprecationWarning: QgsComposition constructor is deprecated but can find nothing about this warning on Google.

  • 1
    did you add from qgis.PyQt.QtXml import QDomDocument Commented Dec 15, 2016 at 23:47
  • Nope. Will try tomorrow
    – raphael
    Commented Dec 15, 2016 at 23:47
  • @MatthiasKuhn that worked. Any idea about the deprecation warning?
    – raphael
    Commented Dec 16, 2016 at 21:53
  • @MatthiasKuhn feel free to turn your comment into an answer
    – raphael
    Commented Dec 28, 2016 at 15:38

1 Answer 1


From this comment, adding the following line to the console script resolved this issue in 2.14 to 2.18.2

from qgis.PyQt.QtXml import QDomDocument

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.