Question by
Crayder · Feb 21, 2016 at 02:15 AM ·
xmlparsinglinqienumerable
IEnumerable Elements 'Where' and 'Select' In Unity?
I have a C# program that has a function that reads an XML. I took that function and brought it over to my Unity game which will be using the same XML. However, my reading method doesn't seem to work.
Libraries:
using System.Xml;
using System.Xml.Linq;
Reader:
static public XDocument ProjectXML = XDocument.Load(SaveHandler.gFolder + "xml");
List<XElement> GameInfo = ProjectXML.Descendants("Project").Elements("Subsystems").Elements("Values").Where(x => x.Attribute("Name").Value == "GameInfo").Elements("Value").ToList();
foreach (XElement elem in GameInfo)
{
if (elem.Attribute("Name").Value == "TerrainGenerationMode")
GenerationMode = (elem.Attribute("Value").Value == "Flat");
if (elem.Attribute("Name").Value == "WorldName")
WorldName = elem.Attribute("Value").Value;
if (elem.Attribute("Name").Value == "TerrainLevel")
TerrainLevel = int.Parse(elem.Attribute("Value").Value);
if (elem.Attribute("Name").Value == "TerrainBlockIndex")
TerrainBlock = int.Parse(elem.Attribute("Value").Value);
if (elem.Attribute("Name").Value == "TerrainOceanBlockIndex")
OceanBlock = int.Parse(elem.Attribute("Value").Value);
}
PlayerPosition = new double[3]; // Temporary Line
List<XElement> Player = ProjectXML.Descendants("Project").Elements("Entities").Elements("Entity").Where(x => x.Attribute("Name").Value == "Player").Elements("Values").Where(x => x.Attribute("Name").Value == "Body").Elements("Value").ToList();
foreach (XElement elem in Player)
{
if (elem.Attribute("Name").Value == "Position")
PlayerPosition = elem.Attribute("Value").Value.Split(',').Select(double.Parse).ToArray();
}
That code is perfectly fine in my other program. But apparently Where
and Select
don't exist in Unity's libraries.
So what are my alternatives in Unity?
EDIT, Errors:
Error 1 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' could be found (are you missing a using directive or an assembly reference?) F:\Repositories\SC TB 3D\Assets\Survivalcraft\Settings.cs 22 111 Assembly-CSharp
Error 2 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' could be found (are you missing a using directive or an assembly reference?) F:\Repositories\SC TB 3D\Assets\Survivalcraft\Settings.cs 37 107 Assembly-CSharp
Error 3 'System.Array' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) F:\Repositories\SC TB 3D\Assets\Survivalcraft\Settings.cs 41 75 Assembly-CSharp
Comment
Your answer
Follow this Question
Related Questions
TryParse causing editor/game to freeze 1 Answer
Cant save file into Android internal memory 1 Answer
Inserting '¡' into an XML file. 1 Answer
Error CS8025: Parsing Error 3 Answers
Using Linq with SQLite 2 Answers