Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved QXmlStreamReader fails when child element is on next line?

    General and Desktop
    2
    5
    537
    Loading More Posts
    • 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.
    • Diracsbracket
      Diracsbracket last edited by

      Hi.
      I am using QXmlStreamReader to read an XML file

      <?xml version="1.0" encoding="utf-8"?>
      <rm>
          <nm>Name</nm>
          <if>Info</if>
          <ff>Format</ff>
          <ic>Icon</ic>
          <bt>
              <it><b>Button1</b><c>code</c><i>icon</i></it>
              <it>
      	    <b>Button2</b>
      	    <s>
                      <si><d>Macro1</d><c>code1</c></si>
                      <si><d>Macro2</d><c>code2</c></si>
                  </s>
                  <i>icon</i>
              </it>
       ...
      

      The reader fails when it encounters the first <s> element, printing only:

      D libTest: (null):0 ((null)): "s" "\n                "
      

      errorString() prints the following:

      D libWifi2IR: (null):0 ((null)): "Expected character data."
      

      Once this error occurs, parsing is interrupted and I don't even get the rest of the file.
      How can I avoid this behavior?

      1 Reply Last reply Reply Quote 0
      • Diracsbracket
        Diracsbracket @VRonin last edited by Diracsbracket

        Hi @VRonin
        I just realized that since I am not further querying for the children inside the <s> element at this stage (I do it later, in QML), I should either just skip reading the text for that element, or use

        readElementText(QXmlStreamReader::IncludeChildElements)
        

        instead of just using:

        readElementText()
        

        Somehow, just posting the "problem" helps to clarify things...
        Sorry for the disturbance...

        1 Reply Last reply Reply Quote 1
        • V
          VRonin last edited by

          Can you post your code?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          Diracsbracket 1 Reply Last reply Reply Quote 0
          • Diracsbracket
            Diracsbracket @VRonin last edited by Diracsbracket

            Hi @VRonin
            I just realized that since I am not further querying for the children inside the <s> element at this stage (I do it later, in QML), I should either just skip reading the text for that element, or use

            readElementText(QXmlStreamReader::IncludeChildElements)
            

            instead of just using:

            readElementText()
            

            Somehow, just posting the "problem" helps to clarify things...
            Sorry for the disturbance...

            1 Reply Last reply Reply Quote 1
            • V
              VRonin last edited by

              Just to be clear, since <s> has no text, the error is the correct behaviour for the parser

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              Diracsbracket 1 Reply Last reply Reply Quote 3
              • Diracsbracket
                Diracsbracket @VRonin last edited by Diracsbracket

                @VRonin said in QXmlStreamReader fails when child element is on next line?:

                Just to be clear, since <s> has no text, the error is the correct behaviour for the parser

                Yes, I naively thought that the child elements inside <s> would be considered as the 'value' for that <s> element. Another thing learned today...
                As always, thanks for reacting!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post