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. QXmlStreamReader fails when child element is on next line?

QXmlStreamReader fails when child element is on next line?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 815 Views
  • 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.
  • DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by
    #1

    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
    0
    • VRoninV VRonin

      Can you post your code?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #3

      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
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #2

        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

        DiracsbracketD 1 Reply Last reply
        0
        • VRoninV VRonin

          Can you post your code?

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #3

          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
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #4

            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

            DiracsbracketD 1 Reply Last reply
            3
            • VRoninV VRonin

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

              DiracsbracketD Offline
              DiracsbracketD Offline
              Diracsbracket
              wrote on last edited by Diracsbracket
              #5

              @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
              0

              • Login

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