0

I've got a strange XML-File as an output from another program. I have no control over it and unfortunately I cannot change it. Now I want to read this into a C#-application and work with it.

<?xml version="1.0" encoding="UTF-8"?>
<Table name="UnitData">
<Data type="STRING" header="UnitNumber"/>
<Data type="STRING" header="Date"/>
<Data type="STRING" header="Caller"/>
<Data type="STRING" header="CallerNumber"/>
<Data type="STRING" header="Location"/>
<Data type="STRING" header="Street"/>
<Row>
</Row>
<Row>
<Column value="123456789"/>
<Column value="16.03.2021"/>
<Column value="Person a"/>
<Column value="012-12321"/>
<Column value="London"/>
<Column value="NiceStreet"/>
<Table name="UnitCodes">
<Data type="STRING" header="UnitCodeEC"/>
<Data type="STRING" header="UnitCodeECDesc"/>
<Row>
</Row>
</Table>
<Data type="STRING" header="Name"/>
<Data type="STRING" header="Vorname"/>
<Row>
</Row>
</Table>
<Table name="Units">
<Data type="STRING" header="UnitName"/>
<Data type="STRING" header="UnitLocation"/>
<Data type="STRING" header="AlarmTime"/>
<Data type="STRING" header="EndTime"/>
<Row>
</Row>
<Row>
<Column value="Unit 1-A"/>
<Column value="Location 1"/>
<Column value="16.03.2021-20:11:45"/>
<Column value="16.03.2021-21:27:15"/>
</Row>
<Row>
<Column value="Unit 1-B"/>
<Column value="Location 1"/>
<Column value="16.03.2021-20:11:45"/>
<Column value="16.03.2021-21:27:15"/>
</Row>
<Row>
<Column value="Unit 2-A"/>
<Column value="Location 2"/>
<Column value="16.03.2021-20:11:45"/>
<Column value="16.03.2021-21:27:15"/>
</Row>
</Table>

</Row>
</Table>

I've found a lot of information on how to read XML files, but in no way is the XML file structured that crap way. A table in a table row with a header description.

The structure is always the same, sometimes with more Row's, but even if a value is empty, the Colum is still there. I think i can work with ID's, like in an array

document.row[0][0] = 123456789

document.row[0][3] = Person a

document.row[0].table('Units')[1][0] = Unit 1-B

Any Ideas? Thanks for you help

Xandar
  • 21
  • 6
  • Your XML is not well-formed. Please edit your question and fix it. Additionally, the XML contains at least two tables: **UnitData** and **Units**. – Yitzhak Khabinsky Mar 18 '21 at 16:07
  • Looks like in editing the XML to post it you left out some of the matching open/close tags so now the structure is not well formed; but in any case, take a look here: https://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c – mikelegg Mar 18 '21 at 16:09
  • except for the values, this is exactly the XML format as it was given to me. I know that is not entirely correct. Unfortunately there is nothing I can do about it – Xandar Mar 19 '21 at 08:00

0 Answers0