I am looking to load repeated elements from an XML file I have called initialInspections.xml. The problem is that the system needs to be dynamic and to allow as many different inspectionNotes to be added. I need to input all of them even though they have the same name.
If someone could please give me a method of doing this I would be extremely appreciative, since I have been searching for almost 3 hours now and I haven't found anything that works.
I need all off the data from within each inspectionNote node, and it will be put into an array of a structure called initialInspectionNotes.
Here is what I have up to now:
public int propertyID; public string initialInspectorUsername; public DateTime intialDateTime; public struct initialInspectionNotes { public string locationWithinProperty; public string locationExtraNote; public string costCode; public float estimatedTime; } private void finalInspection_Load(object sender, EventArgs e) { //Open the intialInspections xml file and load the values into the form XmlDocument xdoc = new XmlDocument(); FileStream rFile = new FileStream(values.xmlInitialFileLocation, FileMode.Open); xdoc.Load(rFile); XmlNodeList list = xdoc.GetElementsByTagName("initialInspection"); for (int i = 0; i < list.Count; i++) { XmlElement initialInspection = (XmlElement)xdoc.GetElementsByTagName("initialInspection")[i]; XmlElement initialInspector = (XmlElement)xdoc.GetElementsByTagName("userInspection")[i]; XmlElement dateTime = (XmlElement)xdoc.GetElementsByTagName("dateTime")[i]; propertyID = int.Parse(initialInspection.GetAttribute("propertyID")); initialInspectorUsername = initialInspector.InnerText; intialDateTime = DateTime.Parse(dateTime.InnerText); } rFile.Close(); } The XML looks like this:
<?xml version="1.0" encoding="utf-8"?> <initialInspections> <initialInspection propertyID="1"> <userInspection>defaultadmin</userInspection> <dateTime>07/11/2015 17:15:20</dateTime> <inspectionNote> <location>Dining Room</location> <locationNote>Remove whole carpet, leave underlay</locationNote> <CostCode>L1</CostCode> <estimatedTime>5</estimatedTime> </inspectionNote> <inspectionNote> <location>Other - See Notes</location> <locationNote>On the marked area with orange spray paint.</locationNote> <CostCode>B1</CostCode> <estimatedTime>12</estimatedTime> </inspectionNote> </initialInspection> </initialInspections> Any help would be much appreciated.
No comments:
Post a Comment