QDomDocument doc; doc.setContent("\n "); QDomElement root = doc.documentElement(); int lineNum = root.lineNumber(); qDebug() << "Root element line number: " << lineNum;\n \n
QFile file("doc.xml"); if (!file.open(QIODevice::ReadOnly)) return; QDomDocument doc; doc.setContent(&file); file.close(); QDomElement element = doc.documentElement().firstChildElement("example"); int lineNum = element.lineNumber(); qDebug() << "Example element line number: " << lineNum;This code reads an XML file into a QDomDocument and retrieves an element with the tag name "example". It then calls the `lineNumber()` function to get its line number in the document. The line number is then printed to the console. Package library: Qt (specifically the QDom package)