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. Read specific attribute in xml file

Read specific attribute in xml file

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.5k Views 2 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.
  • N Offline
    N Offline
    Narthan
    wrote on last edited by
    #1

    Hello all,
    i have to read xml file and print a specific attribute name once and values in a file like
    hello:Yes,No,No
    hello1:No,Yes
    hello3:No,No,No

    i have a xml file like
    <Root Name="hello" result= "yes"/>
    <Root Name="hello" result= "No"/>
    <Root Name="hello" result= "No"/>
    <Root Name="hello1" result= "No"/>
    <Root Name="hello1" result= "yes"/>
    <Root Name="hello3" result= "No"/>
    <Root Name="hello3" result= "No"/>
    <Root Name="hello3" result= "No"/>

    how can i do this ? any suggestions ?

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      It depends which API you are using to read XML: Qt provides 3 ways to do it. The recommended QXmlStreamReader allows you to use QXmlStreamReader::attributes() to explorer the attributes of a StartElement.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      N 1 Reply Last reply
      0
      • JohanSoloJ JohanSolo

        It depends which API you are using to read XML: Qt provides 3 ways to do it. The recommended QXmlStreamReader allows you to use QXmlStreamReader::attributes() to explorer the attributes of a StartElement.

        N Offline
        N Offline
        Narthan
        wrote on last edited by
        #3

        @JohanSolo Thanks , i can read a attributes but i want print like this
        hello:Yes,No,No
        hello1:No,Yes
        hello3:No,No,No
        in a another file or in qdebug ?
        how can i achieve this ? any idea ?

        JohanSoloJ 1 Reply Last reply
        0
        • N Narthan

          @JohanSolo Thanks , i can read a attributes but i want print like this
          hello:Yes,No,No
          hello1:No,Yes
          hello3:No,No,No
          in a another file or in qdebug ?
          how can i achieve this ? any idea ?

          JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          @Narthan said:

          @JohanSolo Thanks , i can read a attributes but i want print like this
          in a another file or in qdebug ?
          how can i achieve this ? any idea ?

          QDebug is as the name suggests for debugging mostly (but clearly not only), and usually prints in cerr, therefore if you want to get the output whatever build type, rather go for cout or a file. It's really up to you...

          In order to achieve the wanted counting, you have several choices: QMultiMap, a QMapof QVector, a QHash of QVector, etc. Or you could use a QMap of QString in which you concatenate every "result" field.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Narthan
            wrote on last edited by
            #5

            Thank you :)

            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