Hi
This is the scenario:
I open an XML file with the following content:
<?xml version="1.0" encoding="Windows-1252"?>
<Resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Resource>
<type>container</type>
<codename>resource_crate</codename>
<name>Crate</name>
<health>100</health>
<changeType>null</changeType>
<changeValue>0</changeValue>
<information>A crate that may have some useful items inside.</information>
<mineable>false</mineable>
<tool>null</tool>
<fragments>0</fragments>
<crosshair>crosshairHand</crosshair>
</Resource>
<Resource>
<type>item</type>
<codename>item_waterpellet</codename>
<name>Water pellet</name>
<health>100</health>
<changeType>liquids</changeType>
<changeValue>5</changeValue>
<information>When you feel thirsty.</information>
<mineable>false</mineable>
<tool>null</tool>
<fragments>0</fragments>
<crosshair>crosshairHand</crosshair>
</Resource>
<Resource>
<type>item</type>
<codename>item_nutritionpellet</codename>
<name>Nutrition pellet</name>
<health>100</health>
<changeType>nutrition</changeType>
<changeValue>3</changeValue>
<information>When you feel hungry.</information>
<mineable>false</mineable>
<tool>null</tool>
<fragments>0</fragments>
<crosshair>crosshairHand</crosshair>
</Resource>
</Resources>
I then want to save every Resource in a class that looks like this:
public class resourcesList {
string type;
string codename;
string name;
string health;
string changeType;
string changeValue;
string information;
string mineable;
string tool;
string fragments;
string crosshair;
public resourcesList(string newType, string newCodename, string newName, string newHealth, string newChangeType, string newChangeValue, string newInformation, string newMineable, string newTool, string newFragments, string newCrosshair) {
type = newType;
codename = newCodename;
name = newName;
health = newHealth;
changeType = newChangeType;
changeValue = newChangeValue;
information = newInformation;
mineable = newMineable;
tool = newTool;
fragments = newFragments;
crosshair = newCrosshair;
}
}
To do this I use:
public ArrayList myArrayList = new ArrayList();
void getResources() {
doc.Load(xmlResoursPath);
XmlNode baseNode = doc.DocumentElement; // Resources
XmlNode childNode;
int nTopNodes = baseNode.ChildNodes.Count;
for (int i = 0; i < nTopNodes; i++) {
childNode = baseNode.ChildNodes[i];
myArrayList.Add(new resourcesList(
childNode.SelectSingleNode("type").InnerText,
childNode.SelectSingleNode("codename").InnerText,
childNode.SelectSingleNode("name").InnerText,
childNode.SelectSingleNode("health").InnerText,
childNode.SelectSingleNode("changeType").InnerText,
childNode.SelectSingleNode("changeValue").InnerText,
childNode.SelectSingleNode("information").InnerText,
childNode.SelectSingleNode("mineable").InnerText,
childNode.SelectSingleNode("tool").InnerText,
childNode.SelectSingleNode("fragments").InnerText,
childNode.SelectSingleNode("crosshair").InnerText
));
}
}
But I cant figure out how to get the values “nodevalues” out of it again.
For example: if I want to know the [codename] of the second Resource in the xml file, how do I do that?
By using “Debug.Log(myArrayList[1])” it only show the output “resourcesList”…