hi,
i have created an xml file using Dom , i got errors while opening, please can body tell me how to read xml file using Qt. Attached my program file, please find the attachment.
hi,
i have created an xml file using Dom , i got errors while opening, please can body tell me how to read xml file using Qt. Attached my program file, please find the attachment.
This demonstrates how to open an XML file as a DOM document.
Qt Code:
{ return; } QDomDocument doc; doc.setContent(&file); file.close();To copy to clipboard, switch view to plain text mode
rk0747 (4th February 2010)
hi,
i didn't ask requirement correctly, i want to read the values from xml file into lineedit in the xmledit.ui. After that i want to edit and update the values from xmledit.ui. please tell me if you know how to do this.
Did you read about the QLineEdit class ? how to set and get text ?
My understanding of what you just asked is really two questions:
- How can I read XML from a file (as in an entire file), and place the contents into a line edit control.
- How can I read the full text from a line edit control and save it in a file.
Is this what you desire to do, or is it closer to:
- How can I read XML from a file. I want to then extract a portion of the file and place this portion into a line edit control.
- Later, I want to read the text from the line edit control, and replace a specific portion in the XML
Even as stated, it is not likely to be sufficient information. For example, if you place XML into this control, is the XML a complete and valid portion of XML? After the user edits the XML, do you check it for valid syntax.
My point with this is that your question is a bit vague, at least for me. Also, there is a difference between understanding generally what must be done, but missing a step to work the QT library. For example, I understand how DOM works, but I had a bit of trouble figuring out the nuances of the QT implementation (not that I am an expert).
hi,
i saved value from lineEdit to an xml file. Again i want to read the values from xml file to lineEdit and then modify(edit ) the values and update it. i used Qdomdocument ,Q domelement and Qdomtext to save the values , but facing dificulty to read the values.
my xml file is:
<ECLOGIC>
<PLCNO> 123</PLCNO>
<PLCName>motor pump</PLCName>
</ECLOGIC>
code to save from lineEdit to a xml file:
void xmledit::SaveXMLFile()
{
filename = QFileDialog::getSaveFileName(this,
tr("Save Xml"), ".",
tr("Xml files (*.xml)"));
QFile file(filename);
file.open(QIODevice::WriteOnly);
const int Indent = 4;
QDomDocument doc;
QDomElement root = doc.createElement("ECLogic");
QDomElement Plcwin = doc.createElement("PLCConfig");
QDomText Plcno = doc.createTextNode(ui->PNumber->text());
QDomText Plcname = doc.createTextNode(ui->PNumber->text());
doc.appendChild(root);
root.appendChild(Plcwin);
root.appendChild(Plcwin);
Plcwin.appendChild(Plcno);
Plcwin.appendChild(Plcname);
QTextStream out(&file);
doc.save(out, Indent);
file.close();
now how to read the vaues using xmldom?
You have to read a file and set it contents to dom document, for example:
Qt Code:
QDomDocument doc; if (!doc.setContent(file.readAll())) { qDebug("Parsing failed!"); return; }To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Bookmarks