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. Write data to specific place in a XML file
QtWS25 Last Chance

Write data to specific place in a XML file

Scheduled Pinned Locked Moved Unsolved General and Desktop
xmlsave
2 Posts 2 Posters 853 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.
  • T Offline
    T Offline
    TMJJ
    wrote on last edited by
    #1

    Hi all,

    It's the first time that I'm playing with xml files.
    I have an xml file which will be used on an embedded system to store machine settings.

    I create the following XML file:

    <Machines>
     <Machinename Name="Zaaimachine" ID="0">
    	<Button Name="0" ID="0">	
    		<Function Name=" Clock" ID="0"/>
    			<Output Name="1" ID="0"/>
    				<State Name="0" ID="0"/>
      		<Function Name=" Output" ID="1"/>
    			<Output Name="2" ID="0"/>
    				<State Name="1" ID="0"/>
    ...
    

    can read all the values from the XML file. But now I wish to change some values.

    Let's say I want to change the output name from 2 to 3.
    I store the data in a array:

    JB[0][0] = The function name, in this case: "Output"
    JB[0][1] = The output name, in this case: "2"
    JB[0][2] = The state name, in this case: "1"

    Now I change the value from JB[0][1] to 3:

    JB[0][0] = The function name, in this case: "Output"
    JB[0][1] = The output name, in this case: "3"
    JB[0][2] = The state name, in this case: "1"

    Now I need to write some code to save JB[0][1] into the xml file.
    Can somebody point me in the good direction?

    When I search on the internet I always find you should save the complete xml file into variables and the overwrite the complete file.

    Isn't there a better way?

    Thanks in advance,
    Kind regards,
    TMJJ

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QDomDocument comes to mind for that kind of thing. There's no easy way to modify a file "in-place".

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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