Problem with Read and Write XML File
-
@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
-
What exactly is your problem?
-
@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.
-
@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.
-
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>;
;
;
; -
@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). :-)
-
@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...) :)