I have an XML file full of events like this one with multiple statements to check.
How is this action even called? I'm so lost that I don't even know where to start looking.
<BENEvents>
<BENDescisionQ1 flagBEN_00="true" flagBEN_01="true" flagBEN_28="true" flagBEN_29="false">
<AskQuestions caption='Looking today again at you glass with milk you decide....'>
<Question event='DescisionQ1Yes'>Cowcostumes look great.</Question>
<Question event='DescisionQ1No'>Flatnesss is justice, so NO</Question>
</AskQuestions>
</BENDescisionQ1>
<BENDescisionQ2 ....>
.....
</BENDescisionQ2>
<BENEvents>
Please help to point me in the right direction.
EDIT: THe answer solved my question, thatnk you
This is how my code ended up for now to deal with more general events.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using System.IO;
public class mllhildTestLinq : MonoBehaviour
{
public mllhildTestController controller;
public void QueryXML(string filename, string parentNode, GameObject listForDisplay)//(string[] args)
{
List<GeneralEvent> listEvents = new List<GeneralEvent>();
GeneralEvent GeneralEvents = new GeneralEvent();
listEvents = GeneralEvents.parse(filename, parentNode);
// just printing for testing
//Debug.Log("Is this shit getting here?");
int i = 0;
foreach (GeneralEvent newEvent in listEvents)
{
//Debug.Log(i);
listForDisplay.GetComponent<PrefabListButtoms>().AddNewButton(newEvent.nodeName, listForDisplay);
Debug.Log(newEvent.nodeName);
i++;
foreach (KeyValuePair<string, string> keyValuePair in newEvent.general)
{
Debug.Log(keyValuePair.Key + " " + keyValuePair.Value);
}
//for (int i = 0; i < newEvent.general.Count; i++)
//{
// controller.AddText(" key: " + newEvent.general[i].Key + " value: " + newEvent.general[i].Value);
//}
//controller.AddText("\n");
}
}
}
public class GeneralEvent
{
public static List<GeneralEvent> listEvents = new List<GeneralEvent>();
public string nodeName { get; set; }
public List<KeyValuePair<string, string>> general { get; set; }
//string patternNumber = @"\d+$";
string patternGeneral = @"[^\d]+[^\$]+";
public List<GeneralEvent> parse(string filename, string parentNode)
{
listEvents.Clear();
XElement generalEvents;
XDocument doc = XDocument.Load(filename);
try
{
generalEvents = doc.Descendants(parentNode).First();
//generalEvents = doc.Elements(parentNode).FirstOrDefault();
}
catch
{
generalEvents = null;
}
//XElement generalEvents = doc.Descendants(parentNode).FirstOrDefault();
if (generalEvents != null)
{
//Debug.Log("---------------------------------------------------------------------");
foreach (XElement descision in generalEvents.Elements())
{
GeneralEvent newEvent = new GeneralEvent();
listEvents.Add(newEvent);
//Debug.Log(descision.Name);
// newEvent.nodeName = string.Parse(Regex.Match(descision.Name.LocalName, patternGeneral).Value);
newEvent.nodeName = descision.Name.ToString();
newEvent.general = descision.Attributes()
.Select(x => new KeyValuePair<string, string>(Regex.Match(x.Name.LocalName, patternGeneral).Value, (string)x)).ToList();
}
}
else
{
Debug.Log("null");
}
return listEvents;
}
}