Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

Write data to specific place in a XML file



  • 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


  • Lifetime Qt Champion

    Hi,

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


Log in to reply