Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:39:01+00:00 2026-06-11T15:39:01+00:00

I’m trying to parse XML -file using QXmlStreamReader . With following code I only

  • 0

I’m trying to parse XML-file using QXmlStreamReader. With following code I only get the first testcase from the sample xml file.

from PyQt4.QtCore import QXmlStreamReader, QFile, QIODevice

class TestcaseReader(object):
    def __init__(self, filename):
        file = QFile(filename)
        file.open(QIODevice.ReadOnly)
        self.xml = QXmlStreamReader(file)

        while not self.xml.atEnd():
            self.xml.readNext()
            if self.xml.isStartElement():
                if self.xml.name() == "Testcase":
                    self.parse_testcase()

    def parse_testcase(self):
        print("Parse Testcase")
        while self.xml.readNextStartElement():
            if self.xml.name() == "Type":
                measurement = self.xml.readElementText()
                print("Type: " + measurement)
            elif self.xml.name() == "Attributes":
                name = self.xml.attributes().value("name")
                strname = self.xml.attributes().value("strname")
                elementtype = self.xml.attributes().value("type")
                value = self.xml.attributes().value("value")
                print("Attributes: ", name, strname, elementtype, value)

if __name__ == "__main__":
    print("XML Reader")
    xml = TestcaseReader("test.xml")

Here is my XML file:

<?xml version="1.0" encoding="UTF-8" ?>
<Testcases>
    <Testcase>
        <Type>Testtype1</Type>
        <Attributes name="testattr1" strname="Testattribute 1" type="float" value="1.0">
        <Attributes name="testattr2" strname="Testattribute 2" type="str" value="test">
    </Testcase> 
    <Testcase>
        <Type>Testtype2</Type>
        <Attributes name="testattr1" strname="Testattribute 1" type="float" value="2.0">
        <Attributes name="testattr2" strname="Testattribute 2" type="str" value="test">
    </Testcase>
</Testcases>

After parsing the first Testcase from Testcases QXmlStreamReader returns it is at the end and therefore stops further parsing. How can I read all testcases from the xml file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:39:02+00:00Added an answer on June 11, 2026 at 3:39 pm

    As the data QXmlStreamReader reads the data incrementally, not all data might be available in the QIODevice’s buffer. That’s particularly the case when reading data from a slow device, e.g. a network socket, but can also happen when reading from local files.

    Read more about how to handle data arriving in chunks that in the “Incremental parsing” section of the QXmlStreamReader documentation.

    Also, your XML is invalid, it should read <Attributes ... /> instead of <Attributes ...>. E.g., for the first one:

    <Attributes name="testattr1" strname="Testattribute 1" type="float" value="1.0"/>
    

    QXmlStreamReader’s error(), errorString(), errorLine() and errorColumn() should give you all the information needed to debug such issues. (and it’s good practice to check for errors and report them properly anyway).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.