I am trying to add ids to the QDomElements in cpp. I successfully genearte a kml file. I want to add the ids to the kml tags like Document, Placemark in incremental way. How can I add ids to the tags in kml file.
QDomProcessingInstruction header = createProcessingInstruction(QStringLiteral("xml"), QStringLiteral("version=\"1.0\" encoding=\"UTF-8\""));
appendChild(header);
QDomElement kmlElement = createElement(QStringLiteral("kml"));
kmlElement.setAttribute(QStringLiteral("xmlns"), "http://www.opengis.net/kml/2.2");
QDomElement m_rootDocumentElement; m_rootDocumentElement =
createElement(QStringLiteral("Document"));
kmlElement.appendChild(m_rootDocumentElement);
for(int i = 0; i < qgeoCordinateList.count(); i++){
QDomElement wpPlacemarkElement = createElement("Placemark");
QDomElement wpPlacemarkElement1 = elementById("4");
m_rootDocumentElement.appendChild(wpPlacemarkElement);
wpPlacemarkElement.appendChild(wpPlacemarkElement1);
addTextElement(wpPlacemarkElement, "name", QString::number(i+1));
QDomElement pointElement = createElement("Point");
wpPlacemarkElement.appendChild(pointElement);
addTextElement(pointElement, "Index", QString::number(i));
}
QTextStream stream(&file);
stream << header;
stream << kmlElement;
qDebug() << "kml Data :" << kmlElement.toElement().text().simplified();
file.close();
To add Id into "QDomElement" tag add line where you want to add tag for QDomElement
wpPlacemarkElement.setAttribute(QStringLiteral("id"), QString::number(i));
// i is index of for loop
// add this line into for loop