[SOLVED] First time trying to parse xml file: getting invalid(1)/PrematureEndOfDocumentError
-
Please forgive my numerous posts tonight... this is the first time I have worked with the Qt QXMLStreamReader and I am at a loss as to why it won't read my xml.
Here is the xml file:
@
<?xml version="1.0" encoding="UTF-8"?>
<MachineRoles>
<MachineRole>
<RoleName>TestClient</RoleName>
<BaseRole>client</BaseRole>
<Modes/>
</MachineRole>
<MachineRole>
<RoleName>TestServer</RoleName>
<BaseRole>client</BaseRole>
<Modes>
<Mode>LiveServerMode</Mode>
</Modes>
</MachineRole>
</MachineRoles>
@Here is the code that reads it:
@
// I have checked to make sure that filename contains the correct path
QFile* xmlFile = new QFile(vmXmlDir->absoluteFilePath(filename));
QXmlStreamReader* mXml = new QXmlStreamReader(xmlFile); //using ReadAll() also gives error...
QXmlStreamReader::TokenType token;// = mXml->rea;
while (!mXml->atEnd() && !mXml->hasError())
{
token = mXml->readNext(); // GIVES invalid(1) ON FIRST READNEXT...
if (token == QXmlStreamReader::StartDocument)
continue;
if (token == QXmlStreamReader::StartElement)
{
if (mXml->name() == containerName)
continue;
if (mXml->name() == tag)
baseInstance->fromFile(*this);
}
}if (mXml->hasError())
{
QXmlStreamReader::Error e = mXml->error(); // e is the enumeration: PrematureEndOfDocumentError
}
@EDIT: FYI, this is a generic XML reader method that I will use with all xml files of a certain format. containerName is the base tag, tag is the record tag indicating that a new record has been found in the xml file and needs to be processed.
-
Ok... Duh... I'm an idiot. Maybe its time to go to bed lol. I forgot to open the file...