I need to create an xml file that is supposed to look like this.
<Event id="Date - Event Name - Event Type">
<DogNumber id="dog id number">
<dogName id-"dog id number">dog name</dogName>
<dogBreed>dog breed</dogBreed>
</DogNumber>
</Event>
and then it would repeat again for another event except for different values and attributes for the elements.
<Event id="Date - Event Name - Event Type">
<DogNumber id="dog id number">
<dogName id-"dog id number">dog name</dogName>
<dogBreed>dog breed</dogBreed>
</DogNumber>
</Event>
I am new to creating XML files with C# and am having trouble properly adding the attributes to the element and getting the parent and child nodes the same as I have shown above. I need to be able to look into this file from my C# application and be able to read all of the values listed above based on the particular event and then the particular dog in each event. The criteria of which event and which dog to select will be based upon user input in a ComboBox likely. my plan was to use the getElementById method. However, I have seen so many different ways to do this that I am having trouble deciding what would be the best and most efficient way to do this.
I think easiest method to read/write that xml file would be using XMLSerializer. This approach also enable You to easly bind to data (if You are using WPF for UI)
Create serializable classes:
and then use XmlSerializer to deserialize(example using file):