I am using QGIS 2.4, Python 2.7.5, win 8.1.

I am trying to read layers from QGIS project. When I try define QgsVectorLayer using QDomNode and readXML function, following error appears:

AttributeError: 'QgsVectorLayer' object has no attribute 'readXML'

code is here:

from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import QApplication
from PyQt4.QtXml import *

app = QgsApplication([], True)
print app.initQgis()

doc = QDomDocument()
doc.setContent(QFile("composer.qgs"), False)

layers = doc.elementsByTagName("maplayer")

for x in xrange(layers.count()):
    layerDOM = layers.at(x)
    layer = QgsVectorLayer()


Does anybody know, why does the error appear?

1 Answer 1


method exist but you wrote it uncorrectly

help(QgsVectorLayer.readXml) Help on built-in function readXml:

readXml(...) QgsVectorLayer.readXml(QDomNode) -> bool

  • :) well sorry for that question and thanks a lot! readXML-> readXml Oct 9, 2014 at 4:27

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.