- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
public bool Read_XMl_File (XDocument Xml_Document, ref game_data Game_Data) {
bool Is_Success=false; /* Captures this function's result */
try {
this.Xml_Data = (game_data)Game_Data;
/* Recursively read through entire XML Document */
Xml_Document.Root.RecursivelyProcess (
Process_Child_Element,
Process_Parent_Element_Open,
Process_Parent_Element_Close);
Is_Success = true;
}
catch (Exception ex) { throw ex; }
Game_Data = this.Xml_Data; /* Pass the data back to Xml_Data */
return Is_Success;
}
public static void RecursivelyProcess (
this XElement element,
Action<XElement, int> childAction,
Action<XElement, int> parentOpenAction,
Action<XElement, int> parentCloseAction) {
if (element == null) { throw new ArgumentNullException ("element"); }
element.RecursivelyProcess (0, childAction, parentOpenAction, parentCloseAction);
}
private static void RecursivelyProcess (
this XElement element,
int depth,
Action<XElement, int> childAction,
Action<XElement, int> parentOpenAction,
Action<XElement, int> parentCloseAction) {
if (element == null) { throw new ArgumentNullException ("element"); }
if (!element.HasElements) { /* Reached the deepest child */
if (childAction != null) { childAction (element, depth); }
}
else { /* element has children */
if (parentOpenAction != null) { parentOpenAction (element, depth); }
depth++;
foreach (XElement child in element.Elements ()) {
child.RecursivelyProcess ( depth, childAction, parentOpenAction, parentCloseAction );
}
depth--;
if (parentCloseAction != null) { parentCloseAction (element, depth); }
}
}
}