'How can I write and read coordinates as attributes into xml file using c#
Task: I am trying to write and read XYZ coordinates into an existing XML file using parameters ( serializing and deserializing). The coordinates will be later used to run a robot to the desired coordinates. I am also trying to update or overwrite the XML file with the new coordinates. I was able to do it with a single value for XYZ coordinate.
here is the XML file that I am trying to update
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPreset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ir-s.de/irsprogfirmware/xmlns/version-1-0-0">
<Preset id100="1006873">
<qrCodeChannelsNumber>0</qrCodeChannelsNumber>
<qrCodeHeader />
<fixedPrivateKey />
<descriptionShort>IR-Systeme IFFS HS Mini IRF 15</descriptionShort>
<elfOrHexFileNameRelativePath>_IRS-IFFS\1006873_IRS_IFFS_HS_MN_IRF_15\1006873_irs_iffs_hs_mn_irf_15_v3.3_production.elf</elfOrHexFileNameRelativePath>
<programmEeprom>true</programmEeprom>
<lockbits />
<fusesValues>inElfFile</fusesValues>
<eepromAddressOffsetSerial>1020</eepromAddressOffsetSerial>
<eepromAddressOffsetPrivateKey>1004</eepromAddressOffsetPrivateKey>
<device>atxmega32a4u</device>
<programmer>atmelice</programmer>
<progInterface>pdi</progInterface>
<clockSpeedElfFile>1MHz</clockSpeedElfFile>
<clockSpeedSlow>128kHz</clockSpeedSlow>
<X>36</X>
<x_m>80.6</x_m>
<Y>70.4</Y>
<y_m>48.7</y_m>
</Preset>
</ArrayOfPreset>
This is the code that I have tried.
A button is pressed to update the file with the required parameters
private void Button_1006071(object sender, RoutedEventArgs e)
{
Preset.generatePresetList();
}
public Preset(UInt32 id100, String descriptionShort, String elfOrHexFileNameRelativePath, String lockbits, String fusesValues, UInt16 eepromAddressOffsetSerial, UInt16 eepromAddressOffsetPrivateKey, String device, String programmer, String progInterface, String clockSpeedElfFile, String clockSpeedSlow, Byte qrCodeChannelsNumber, String qrCodeHeader, String fixedPrivateKey, bool programmEeprom, float X_coordinate_1, float x_m_coordinate_1, float Y_coordinate_1, float y_m_coordinate_1, float QRX_coordinate_1, float QRY_coordinate_1, float QRX_1_coordinate_1)
{
this.id100 = id100;
this.descriptionShort = descriptionShort;
this.elfOrHexFileNameRelativePath = elfOrHexFileNameRelativePath;
this.lockbits = lockbits;
this.fusesValues = fusesValues;
this.eepromAddressOffsetSerial = eepromAddressOffsetSerial;
this.eepromAddressOffsetPrivateKey = eepromAddressOffsetPrivateKey;
this.device = device;
this.programmer = programmer;
this.progInterface = progInterface;
this.clockSpeedElfFile = clockSpeedElfFile;
this.clockSpeedSlow = clockSpeedSlow;
this.qrCodeChannelsNumber = qrCodeChannelsNumber;
this.qrCodeHeader = qrCodeHeader;
this.fixedPrivateKey = fixedPrivateKey;
this.programmEeprom = programmEeprom;
this.X_coordinate_1 = X_coordinate_1;
this.x_m_coordinate_1 = x_m_coordinate_1;
this.Y_coordinate_1 = Y_coordinate_1;
this.y_m_coordinate_1 = y_m_coordinate_1;
this.QRX_coordinate_1 = QRX_coordinate_1;
this.QRY_coordinate_1 = QRY_coordinate_1;
this.QRX_1_coordinate_1 = QRX_1_coordinate_1;
}
Then call the below function that has the parameters
static public void generatePresetList()
{
ObservableCollection<Preset> presetList = new ObservableCollection<Preset>();
Preset presetCuSy10 = new Preset(1006071, // id100,
"Control Unit Simply CAN 10", // descriptionShort
"_IRS-IFFS\\1006071_IRS_IFFS_CU_SY_CAN_10\\1006071_irs_iffs_cu_sy_can_10_v2.2_production.elf", // elfOrHexFileNamePath
"FC", // lockbits,
"inElfFile", // Fuse Value
0x07FC, // eepromAddressOffsetSerial
0x07EC, // eepromAddressOffsetPrivateKey
"atxmega32a4u", // device,
"atmelice", // programmer,
"pdi", // progInterface,
"1MHz", // clockSpeedElfFile,
"128kHz", // clockSpeedSlow
10, // qrCodeChannelsNumber
"IRS-GLOBAL-1.0", // qrCodeHeader
"",
true,
216.70f,
80.60f,
70.10f,
48.7f,
22f,
57.5f,
80f) ;
presetList.Add(presetCuSy10);
presetList = new ObservableCollection<Preset>(presetList.OrderBy(o => o.id100));
serializeListToXML(presetList);
}
And then I am able to serialize and deserialize.
Now I am trying to find a way to Add twelve XYZ coordinates as attributes. For example. I would like to create something like this
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPreset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ir-s.de/irsprogfirmware/xmlns/version-1-0-0">
<Preset id100="1006873">
.
.
.
<eepromAddressOffsetPrivateKey>1004</eepromAddressOffsetPrivateKey>
<Coordinate 1 X_Axis ="36" Y_Axis ="70.30" Z_Axis = "0.00"/>
<Coordinate 1 X_Axis ="47" Y_Axis ="80" Z_Axis = "0.00"/>
<Coordinate 1 X_Axis ="40" Y_Axis ="100.30" Z_Axis = "0.00"/>
</Preset>
</ArrayOfPreset>
I would highly appreciate if someone could help me create the above code without making too many changes to the function generatePresetList() function. Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
