Updating values in XML file

Hi Forum,

I have been looking around for a solution/example for my problem, but haven't been able to find one out there, so hopefully some helpful Arduino experts in here can give me some tips, link or snippets I can use to solve my problem.

My HW: Arduino board (mega) and an ethernetshield (wired with SD card)

First a bit about my project: I would like to exchange data between my Arduino and a webpage via and XML file, both web page and XML file is stored on a SD card. This first part I got working, reading the XML file from the SD card and sending it to the webpage when it is requested, all this is via the Arduino used as my web server, and using the on board SD card slot on the ethernet shield.

I have seen this example: Arduino Webserver Input and Output but unfortunately it is limited to only a couple of signals to be exchanged between Arduino and a webpage, and the XML file is not stored on the SD card.

The data I want to exchange is approx 200 groups, which each contain 5 variables and my XML is setup so it correspond to this, see below.

<?xml version = "1.0" ?>
  <group name="1">
      <variable id1="on" id2="on" id3="off" id4="on" id5="off" />
  <group name="2">
      <variable id1="on" id2="on" id3="off" id4="on" id5="off" />
  <group name="3">
      <variable id1="on" id2="on" id3="off" id4="on" id5="off" />
  <group name="200">
      <variable id1="on" id2="on" id3="off" id4="on" id5="off" />

My problem is, I want to update a single variable in one of the groups, say e.g. I want to update variable id3 in group 156 from "on" to "off". How to do that in the XML file stored on the SD card. I have been able to read the XML file into a String object in Arduino, but how do I find variable 3 in group 156 and only change the value for this and the save the XML file back to the SD card, so next time the webpage request the XML file it will receive the updated XML file.

Does any one here in the forum have an easy way to achieve this, maybe a XML library that can help with doing these operations, or maybe have another idea how to exchange (big amount) of data between Arduino and a webpage.


Sorry for my english...

using xml you can define multiple levels of information...


<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Address">
        <xs:element name="Recipient" type="xs:string" />
        <xs:element name="House" type="xs:string" />
        <xs:element name="Street" type="xs:string" />
        <xs:element name="Town" type="xs:string" />
        <xs:element name="County" type="xs:string" minOccurs="0" />
        <xs:element name="PostCode" type="xs:string" />
        <xs:element name="Country">
            <xs:restriction base="xs:string">
              <xs:enumeration value="FR" />
              <xs:enumeration value="DE" />
              <xs:enumeration value="ES" />
              <xs:enumeration value="UK" />
              <xs:enumeration value="US" />

You must only modify the parser into the arduino and into the webpage fron the tutorial link

It would be easier if you coded the on off as a single digit e.g. 0 1 as than you could replace the value in the file without moving bytes.

It would help if you could calculate the start position of each group.
But as sizes of texts differ the best you might do is create a lookup table which says

record 156 -> file loc 3289

do an seek to position 3289 and read the bytes until you found the field to update.

That said - why not using an array of 200 bytes in memory reflecting that XML file?
and write that file in binary format to the SD card.