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. Problem with Read and Write XML File
QtWS25 Last Chance

Problem with Read and Write XML File

Scheduled Pinned Locked Moved Solved General and Desktop
xmlxml parsingqt 5.5
10 Posts 3 Posters 3.8k 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.
  • P Offline
    P Offline
    Punit
    wrote on 12 Jul 2016, 12:39 last edited by Punit 7 Dec 2016, 12:42
    #1

    @Lifetime-Qt-Champion @Moderators
    Hello,

    I want to read an xml file and write some values.
    Example:

    <Entry Name="Browser.Dir.Triffort" Type="6" Value="Macintosh:Users:macwaves:Desktop:Jason:;Macintosh:Users:macwaves:Desktop:Max:;Macintosh:Users:macwaves:Desktop:Lucy:"></Entry>
    

    I just want to check if Xml file contains "Entry Name="Browser.Dir.Triffort" Type="6" and if it contains I want to replace the value.

    Just Like: if match found, then

    Value="Macintosh:Users:macwaves:Desktop:Jason:;Macintosh:Users:macwaves:Desktop:Max:;Macintosh:Users:macwaves:Desktop:Lucy:"></Entry>

    TO

    Value=Macintosh:Users:macwaves:XYZ:;"></Entry>

    Any Suggestions? I am using QXmlStreamReader.

    Thanks

    T 1 Reply Last reply 13 Jul 2016, 05:59
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 12 Jul 2016, 14:53 last edited by
      #2

      What exactly is your problem?

      1 Reply Last reply
      0
      • P Punit
        12 Jul 2016, 12:39

        @Lifetime-Qt-Champion @Moderators
        Hello,

        I want to read an xml file and write some values.
        Example:

        <Entry Name="Browser.Dir.Triffort" Type="6" Value="Macintosh:Users:macwaves:Desktop:Jason:;Macintosh:Users:macwaves:Desktop:Max:;Macintosh:Users:macwaves:Desktop:Lucy:"></Entry>
        

        I just want to check if Xml file contains "Entry Name="Browser.Dir.Triffort" Type="6" and if it contains I want to replace the value.

        Just Like: if match found, then

        Value="Macintosh:Users:macwaves:Desktop:Jason:;Macintosh:Users:macwaves:Desktop:Max:;Macintosh:Users:macwaves:Desktop:Lucy:"></Entry>

        TO

        Value=Macintosh:Users:macwaves:XYZ:;"></Entry>

        Any Suggestions? I am using QXmlStreamReader.

        Thanks

        T Offline
        T Offline
        the_
        wrote on 13 Jul 2016, 05:59 last edited by
        #3

        @Punit said:

        @Lifetime-Qt-Champion @Moderators
        Why only to these? ;)

        Example:

        <Entry Name="Browser.Dir.Triffort" Type="6" Value="Macintosh:Users:macwaves:Desktop:Jason:;Macintosh:Users:macwaves:Desktop:Max:;Macintosh:Users:macwaves:Desktop:Lucy:"></Entry>
        

        Is this the only content of your XML file? If yes, then it is not valid XML.

        -- No support in PM --

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Punit
          wrote on 13 Jul 2016, 06:05 last edited by
          #4

          @Wieland

          I have a xml file which looks like this:

          <Entry Name="Browser.Dir.Recordings" Type="3" Value="Macintosh:Users:macwaves:Music:My:Recordings:"></Entry>
          
          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:macwaves:Documents:xml 2.10.2:"></Entry>
          
          <Entry Name="Browser.ID3Mode" Type="1" Value="2"></Entry>
          
          <Entry Name="Browser.ImportMusicFolderAtStartup" Type="0" Value="1"></Entry>
          
          <Entry Name="Browser.KeyNotation.Displayed" Type="1" Value="2"></Entry>
          
          

          So the file contains many elements, attributes and values. Now I want to check that if "Entry" element has a value "Browser.Dir.Root" and "Type" element is equals to "3". Like this:

          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:macwaves:Documents:xml 2.10.2:"></Entry>

          Now if match found, I want to change the text in "Value" element. Like this:

          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:macwaves:Documents:xml 2.10.2:"></Entry>

          In the above example, <Entry Name="Browser.Dir.Root" and Type="3".... So match found. Now I want to change text for "Value" like this.

          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:Hello"></Entry>

          So :

          Before:
          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:macwaves:Documents:xml 2.10.2:"></Entry>

          After:
          <Entry Name="Browser.Dir.Root" Type="3" Value="Macintosh:Users:Hello"></Entry>

          How can I achieve this? I don't know much about Xml. Hope you can understand my problem.

          Thanks.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Punit
            wrote on 13 Jul 2016, 06:10 last edited by
            #5

            @the_

            No, I was just showing an element.

            My file looks like this....

            <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
            <NIXML><Settings><Entry Name="Audio.DeviceName" Type="3" Value=""></Entry>
            <Entry Name="Audio.DeviceName.BuiltIn.Win" Type="3" Value=""></Entry>
            <Entry Name="Audio.DeviceName.Mac" Type="3" Value="Built-in"></Entry>
            <Entry Name="Audio.DeviceName.Win" Type="3" Value=""></Entry>
            <Entry Name="Audio.DriverName" Type="3" Value=""></Entry>
            <Entry Name="Audio.FS.Latency" Type="1" Value="512"></Entry>
            <Entry Name="Audio.FS.SampleRate" Type="1" Value="44100"></Entry>
            <Entry Name="Audio.FX.Selection" Type="5" Value="13;19;1;2;3;17;14;29;7;8;9;10;11;12;4;5;6;15;16;18;28;25;24;26;27;31;32;33;34;35;36;37;42;58;59;74;76;87;56;89;84;62;85"></Entry>
            <Entry Name="Audio.Latency" Type="1" Value="512"></Entry>
            <Entry Name="Audio.Mode" Type="1" Value="0"></Entry>
            <Entry Name="Audio.SampleRate" Type="1" Value="44100"></Entry>
            <Entry Name="AudioSettings.InactiveDevices" Type="7" Value="AudioDeviceSettingStart;1.01;Built-in;0;1;44100;512;0;6;12;14;0;1;-1;-1;-1;-1;0;1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;0;1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;AudioDeviceSettingEnd"></Entry>
            <Entry Name="BackgroundThread.AutoAnalyze" Type="0" Value="0"></Entry>
            <Entry Name="BackgroundThread.AutoAnalyzeOnLoad" Type="0" Value="0"></Entry>
            <Entry Name="BackgroundThread.DetermineTime" Type="0" Value="0"></Entry>
            <Entry Name="Broadcast.IcecastMetadata.Genre" Type="3" Value="Mixed Styles"></Entry>
            <Entry Name="Broadcast.IcecastMetadata.URL" Type="3" Value=""></Entry>
            <Entry Name="Broadcast.IcecastServer.Address" Type="3" Value=""></Entry>

            ;
            ;
            ;
            ;

            T 1 Reply Last reply 13 Jul 2016, 06:18
            0
            • P Punit
              13 Jul 2016, 06:10

              @the_

              No, I was just showing an element.

              My file looks like this....

              <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
              <NIXML><Settings><Entry Name="Audio.DeviceName" Type="3" Value=""></Entry>
              <Entry Name="Audio.DeviceName.BuiltIn.Win" Type="3" Value=""></Entry>
              <Entry Name="Audio.DeviceName.Mac" Type="3" Value="Built-in"></Entry>
              <Entry Name="Audio.DeviceName.Win" Type="3" Value=""></Entry>
              <Entry Name="Audio.DriverName" Type="3" Value=""></Entry>
              <Entry Name="Audio.FS.Latency" Type="1" Value="512"></Entry>
              <Entry Name="Audio.FS.SampleRate" Type="1" Value="44100"></Entry>
              <Entry Name="Audio.FX.Selection" Type="5" Value="13;19;1;2;3;17;14;29;7;8;9;10;11;12;4;5;6;15;16;18;28;25;24;26;27;31;32;33;34;35;36;37;42;58;59;74;76;87;56;89;84;62;85"></Entry>
              <Entry Name="Audio.Latency" Type="1" Value="512"></Entry>
              <Entry Name="Audio.Mode" Type="1" Value="0"></Entry>
              <Entry Name="Audio.SampleRate" Type="1" Value="44100"></Entry>
              <Entry Name="AudioSettings.InactiveDevices" Type="7" Value="AudioDeviceSettingStart;1.01;Built-in;0;1;44100;512;0;6;12;14;0;1;-1;-1;-1;-1;0;1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;0;1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;AudioDeviceSettingEnd"></Entry>
              <Entry Name="BackgroundThread.AutoAnalyze" Type="0" Value="0"></Entry>
              <Entry Name="BackgroundThread.AutoAnalyzeOnLoad" Type="0" Value="0"></Entry>
              <Entry Name="BackgroundThread.DetermineTime" Type="0" Value="0"></Entry>
              <Entry Name="Broadcast.IcecastMetadata.Genre" Type="3" Value="Mixed Styles"></Entry>
              <Entry Name="Broadcast.IcecastMetadata.URL" Type="3" Value=""></Entry>
              <Entry Name="Broadcast.IcecastServer.Address" Type="3" Value=""></Entry>

              ;
              ;
              ;
              ;

              T Offline
              T Offline
              the_
              wrote on 13 Jul 2016, 06:18 last edited by
              #6

              @Punit

              You may have a look at QDomDocument.

              -- No support in PM --

              ? 1 Reply Last reply 13 Jul 2016, 09:36
              3
              • P Offline
                P Offline
                Punit
                wrote on 13 Jul 2016, 09:22 last edited by
                #7

                @the_

                Problem is solved. Thanks a lot for your suggestion. :)

                1 Reply Last reply
                0
                • T the_
                  13 Jul 2016, 06:18

                  @Punit

                  You may have a look at QDomDocument.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on 13 Jul 2016, 09:36 last edited by
                  #8

                  @the_ I was just about to yell at you for recommending QDomDocument (Qt Xml module) as it is deprecated. Turns out, it's no longer deprecated anymore (see QTBUG-32926). :-)

                  T 1 Reply Last reply 13 Jul 2016, 09:49
                  2
                  • ? A Former User
                    13 Jul 2016, 09:36

                    @the_ I was just about to yell at you for recommending QDomDocument (Qt Xml module) as it is deprecated. Turns out, it's no longer deprecated anymore (see QTBUG-32926). :-)

                    T Offline
                    T Offline
                    the_
                    wrote on 13 Jul 2016, 09:49 last edited by
                    #9

                    @Wieland
                    I did not notice that it has been depecated in any older Qt Version as I used QXmlStream{Reader,Writer} the one and only time I had to play with XML (I for myself do not like this format...) :)

                    -- No support in PM --

                    ? 1 Reply Last reply 13 Jul 2016, 10:19
                    2
                    • T the_
                      13 Jul 2016, 09:49

                      @Wieland
                      I did not notice that it has been depecated in any older Qt Version as I used QXmlStream{Reader,Writer} the one and only time I had to play with XML (I for myself do not like this format...) :)

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 13 Jul 2016, 10:19 last edited by
                      #10

                      @the_ said:

                      I for myself do not like this format...

                      No-one does ^_^

                      1 Reply Last reply
                      2

                      10/10

                      13 Jul 2016, 10:19

                      • Login

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