Hi all,
i want to retrive some values from a XML,here is the XML
<?xml version="1.0"?>
<transforms>
<Happy>
<FacePosition>
<x>7</x>
<y>8</y>
<z>9</z>
</FacePosition>
<FaceRotation>
<x>1</x>
<y>2</y>
<z>3</z>
</FaceRotation>
<EyeRotation>
<x>4</x>
<y>5</y>
<z>6</z>
</EyeRotation>
</Happy>
<nervous>
<FacePosition>
<x>1</x>
<y>2</y>
<z>3</z>
</FacePosition>
<FaceRotation>
<x>4</x>
<y>5</y>
<z>6</z>
</FaceRotation>
<EyeRotation>
<x>7</x>
<y>8</y>
<z>9</z>
</EyeRotation>
</nervous>
</transforms>
Here’s the method to retrive the values
public static Vector3 LoadFromXml(string elementName,string typename)
{
float X = 0;
float Y = 0;
float Z = 0;
string filepath = Application.dataPath + @"/Resources/Data.xml";
//string filepath = Resources.Load("Data");
XmlDocument xmlDoc = new XmlDocument();
if(File.Exists (filepath))
{
xmlDoc.Load(filepath);
XmlNodeList transformList = xmlDoc.GetElementsByTagName(elementName);
foreach (XmlNode transformInfo in transformList)
{
XmlNodeList transformcontent = transformInfo.ChildNodes;
foreach (XmlNode transformItens in transformcontent)
{
if(transformItens.Name == "x")
{
X = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the Y variable.
}
if(transformItens.Name == "y")
{
Y = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the Y variable.
}
if(transformItens.Name == "z")
{
Z = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the Y variable.
}
}
}
}
return new Vector3(X,Y,Z);;
}
here element name is the name of the state which could be happy or nervous and type name is the name of the sub element facerotation or faceposition or eye rotation.i want to retrive coordinates for a specific state and its subelement.
please help me out i am completely new to XML