0

I have member function for parsing XML like this:

void xmlparser::parsingFunction()
{
    while(1)
    {
        QFile file("info.xml");
        if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            qDebug("Failed to open file for reading");
        }

        QDomDocument document;

        if(!document.setContent(&file))
        {
            qDebug("Failed to parse the file into a Dom tree");
            file.close();
        }
        file.close();

        QDomElement documentElement = document.documentElement();

        QDomNode node = documentElement.firstChildElement();

        while(!node.isNull())
        {
            if(node.isElement())
            {
                QDomElement first = node.toElement();
                emit xmlParsed(first.tagName());
                sleep(5);
            }
            node.nextSibling();
        }
    }
}

My xml tree looks like this http://pastebin.com/nFMJKcmU

I am not sure why It doesn't show all the available tags in root element info

1 Answer 1

1

You've made some errors while retyping from official documentation example. Please, take a look at its typical usage described in QDomDocument Class documentation. So your code must look like:

QDomElement docElem = document.documentElement();
QDomNode n = docElem.firstChild();
while (!n.isNull()) {
    // Try to convert the node to an element.
    QDomElement e = n.toElement();
    if (!e.isNull()) {
        // The node really is an element.
        qDebug() << qPrintable(e.tagName()) << endl;
    }
    n = n.nextSibling();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.