I used DOM to parse an XML file
if (!node.isNull()) {
node = findTag(node, "Communication");
//do something with node
}
{
if (node.toElement().tagName() == tag) {
return node;
}else {
if (hasChild(node)) {
node = node.firstChild();
findTag(node, tag);
}else {
while (!hasSibling(node)) {
if (hasParent(node))
node = node.parentNode();
else
QMessageBox::information(0,
"Error",
"Can not find Tag");
}
node = node.nextSibling();
findTag(node, tag);
}
}
}
inline bool DomParser
::hasParent(const QDomNode &node
) {
if( !node.parentNode().isNull())
return true;
else
return false;
}
inline bool DomParser
::hasSibling(const QDomNode &node
) {
if( !node.nextSibling().isNull())
return true;
else
return false;
}
inline bool DomParser
::hasChild(const QDomNode &node
) {
return node.hasChildNodes();
}
QDomNode node = root.firstChild();
if (!node.isNull()) {
node = findTag(node, "Communication");
//do something with node
}
QDomNode DomParser::findTag(QDomNode &node, const QString &tag)
{
if (node.toElement().tagName() == tag) {
return node;
}else {
if (hasChild(node)) {
node = node.firstChild();
findTag(node, tag);
}else {
while (!hasSibling(node)) {
if (hasParent(node))
node = node.parentNode();
else
QMessageBox::information(0, "Error", "Can not find Tag");
}
node = node.nextSibling();
findTag(node, tag);
}
}
}
inline bool DomParser::hasParent(const QDomNode &node)
{
if( !node.parentNode().isNull())
return true;
else
return false;
}
inline bool DomParser::hasSibling(const QDomNode &node)
{
if( !node.nextSibling().isNull())
return true;
else
return false;
}
inline bool DomParser::hasChild(const QDomNode &node)
{
return node.hasChildNodes();
}
To copy to clipboard, switch view to plain text mode
There is always an error in "qatomic_windows.h"
inline int q_atomic_decrement(volatile int *ptr)
{ return _InterlockedDecrement(reinterpret_cast<volatile long *>(ptr)); }
inline int q_atomic_decrement(volatile int *ptr)
{ return _InterlockedDecrement(reinterpret_cast<volatile long *>(ptr)); }
To copy to clipboard, switch view to plain text mode
Is there anything wrong in my code ?
Bookmarks