ok, so I have a xml file... smth like this:
<?xml version = "1.0" ?>
<!-- My Bookmarks -->
<db>
<user nr="1">
<username>Leoha_Zveri</username>
<password>testpass</password>
</user>
</db>
<?xml version = "1.0" ?>
<!-- My Bookmarks -->
<db>
<user nr="1">
<username>Leoha_Zveri</username>
<password>testpass</password>
</user>
</db>
To copy to clipboard, switch view to plain text mode
in my code i have a function:
bool DOMtraverseNode(const QDomNode& domNode) {
while( !node.isNull() )
{
if ( node.isElement() )
{
qDebug() << "Element: " << element.tagName();
qDebug() << "Element attribute name: " << element.attribute("nr", "not set");
}
if (node.isText())
{
qDebug() << text.data();
}
DOMtraverseNode(node);
node = node.nextSibling();
}
}
bool DOMtraverseNode(const QDomNode& domNode) {
QDomNode node = domNode.firstChild();
while( !node.isNull() )
{
if ( node.isElement() )
{
QDomElement element = node.toElement();
qDebug() << "Element: " << element.tagName();
qDebug() << "Element attribute name: " << element.attribute("nr", "not set");
}
if (node.isText())
{
QDomText text = node.toText();
qDebug() << text.data();
}
DOMtraverseNode(node);
node = node.nextSibling();
}
}
To copy to clipboard, switch view to plain text mode
and in main:
{
qDebug("Failed to open file for reading.");
return -1;
}
if (!document.setContent(&file))
{
qDebug("Failed to parse the file into a DOM tree.");
file.close();
return -1;
}
DOMtraverseNode(domNode);
file.close();
QFile file("admin.xml");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug("Failed to open file for reading.");
return -1;
}
QDomDocument document;
if (!document.setContent(&file))
{
qDebug("Failed to parse the file into a DOM tree.");
file.close();
return -1;
}
QDomElement domNode = document.documentElement();
DOMtraverseNode(domNode);
file.close();
To copy to clipboard, switch view to plain text mode
the question is... how do I check if a 2 QStrings (for example "uname" and "pass" ) entered by the user match, the values from the xml? I can check them separately, returning something from function when it matches the username, and another time when it matches the password,... but what if the xml looks like this:
<?xml version = "1.0" ?>
<!-- My Bookmarks -->
<db>
<user nr="1">
<username>Leoha_Zveri</username>
<password>testpass2</password>
</user>
<user nr="2">
<username>Leoha_Zveri2</username>
<password>testpass</password>
</user>
</db>
<?xml version = "1.0" ?>
<!-- My Bookmarks -->
<db>
<user nr="1">
<username>Leoha_Zveri</username>
<password>testpass2</password>
</user>
<user nr="2">
<username>Leoha_Zveri2</username>
<password>testpass</password>
</user>
</db>
To copy to clipboard, switch view to plain text mode
... functions will return that both values are contained in xml, and it will allow to log in, but it's wrong...
so how can i make this work?
sorry for my bad english...
please someone help
Bookmarks