Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] First time trying to parse xml file: getting invalid(1)/PrematureEndOfDocumentError
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] First time trying to parse xml file: getting invalid(1)/PrematureEndOfDocumentError

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 757 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    primem0ver
    wrote on 14 Sept 2014, 09:02 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      primem0ver
      wrote on 14 Sept 2014, 09:26 last edited by
      #2

      Ok... Duh... I'm an idiot. Maybe its time to go to bed lol. I forgot to open the file...

      1 Reply Last reply
      0

      1/2

      14 Sept 2014, 09:02

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved