Hi All
I am just a beginner of Qt. So Pls excuse me if I have made some silly errors. I was trying to parse a simple XML file and wanted to show it on a simple interface. I have got the code here...
test.cpp
#include<qfile.h>
#include<qdom.h>
#include<iostream.h>
QFile file("simple.xml");
{
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;
}
file.close();
QDomElement documentElement
= document.
documentElement();
while(!node.isNull())
{
if(node.isElement())
{
cout<<"Element"<<element.tagName();
cout<<"Element attribute name"<<element.attribute("name", "not set")
}
if (node.isText())
{
qDebug << text.data();
}
node=node.nextSibling();
}
#include<qfile.h>
#include<qdom.h>
#include<iostream.h>
QFile file("simple.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;
}
file.close();
QDomElement documentElement = document.documentElement();
QDomNode node = document.firstChild();
while(!node.isNull())
{
if(node.isElement())
{
QDomElement element = node.toElement();
cout<<"Element"<<element.tagName();
cout<<"Element attribute name"<<element.attribute("name", "not set")
}
if (node.isText())
{
QDomText text = node.toText();
qDebug << text.data();
}
node=node.nextSibling();
}
To copy to clipboard, switch view to plain text mode
This is the error which I got.
test.cpp:6: error: expected unqualified-id before ‘if’
test.cpp:13: error: expected unqualified-id before ‘if’
test.cpp:20: error: expected constructor, destructor, or type conversion before ‘.’ token
test.cpp:24: error: expected unqualified-id before ‘while’
make: *** [test.o] Error 1
test.cpp:6: error: expected unqualified-id before ‘if’
test.cpp:13: error: expected unqualified-id before ‘if’
test.cpp:20: error: expected constructor, destructor, or type conversion before ‘.’ token
test.cpp:24: error: expected unqualified-id before ‘while’
make: *** [test.o] Error 1
To copy to clipboard, switch view to plain text mode
and here is the XML file
<document name="DocName">
<author name="AuthorName" />
</document>
<document name="DocName">
<author name="AuthorName" />
</document>
To copy to clipboard, switch view to plain text mode
If anyone could help it would be absolute gr8!!!!
Cheers
Shiva
Bookmarks