本文整理汇总了C#中XmlDocument.GetElementById方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.GetElementById方法的具体用法?C# XmlDocument.GetElementById怎么用?C# XmlDocument.GetElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.GetElementById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTranslationTable
public DataTable GetTranslationTable(string languageFilePath, string sourceLanguage, string targetLanguage)
{
DataTable LanguageTbl = new DataTable();
string SrcLanguageFileName = string.Empty;
string TrgLanguagefileName = string.Empty;
string Key = string.Empty;
string SourceValue = string.Empty;
string TargetValue = string.Empty;
LanguageTbl = CreateLanguageTable();
SrcLanguageFileName = languageFilePath + sourceLanguage + ".xml";
TrgLanguagefileName = languageFilePath + targetLanguage + ".xml";
XmlDocument xmlDocSource = new XmlDocument();
xmlDocSource.Load(SrcLanguageFileName);
XmlNodeList xmlNodeList = xmlDocSource.SelectNodes("root/Row");
XmlDocument xmlDocTarget = new XmlDocument();
xmlDocTarget.Load(TrgLanguagefileName);
XmlElement Element;
foreach (XmlNode xmlNode in xmlNodeList)
{
Key = xmlNode.Attributes[0].Value;
SourceValue = xmlNode.Attributes[1].Value;
//Find key value in target language file.
Element = xmlDocTarget.GetElementById(Key);
try
{
TargetValue = Element.Attributes["value"].Value;
}
catch (Exception ex)
{
TargetValue = "";
Global.CreateExceptionString(ex, null);
}
InsertDataIntoLanguageTbl(Key, SourceValue, TargetValue, LanguageTbl);
}
return LanguageTbl;
}
示例2: Load
/*
* Use
* string unitString must contain .xml at the end, otherwise Load won't find the file
*/
public Unit Load(string unitString)
{
filePath = "Assets/Units/";
xFile = new XmlDocument();
xFile.Load(filePath + unitString);
// Start reading the file and pulling data out of it
Unit unit = new Unit();
unit.Name = xFile.GetElementById("name").InnerText;
unit.type = xFile.GetElementById("type").InnerText;
unit.lifepoints = int.Parse(xFile.GetElementById("hp").InnerText); // TODO: fix lifepoints versus hp, might create confusion
unit.damage = int.Parse(xFile.GetElementById("dmg").InnerText);
unit.hull = int.Parse( xFile.GetElementById("hull").InnerText);
unit.price = int.Parse(xFile.GetElementById("price").InnerText);
unit.productionTime = int.Parse(xFile.GetElementById("productiontime").InnerText);
return unit;
}
示例3: GenarateGrid
public void GenarateGrid(string Type ,float Difficalt)
{
// Background = Instantiate(Resources.Load("Prefab/Forest"), new Vector3(0, 2.5f, 0), Quaternion.identity) as GameObject;
_Background = Camera.main.transform.FindChild("Background").GetComponent<Background>();
//
float Rand = 0f; //Рандомная величина
GameObject Now; //Переменная для поиска спаунящегося блока
TextAsset xmlAsset = Resources.Load("LevelStats/" + Type) as TextAsset; //Считываня xml
XmlDocument xmlDoc = new XmlDocument();
if (xmlAsset)
xmlDoc.LoadXml(xmlAsset.text);
XmlElement Stats = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("Location");
Height = Convert.ToInt16(Stats.GetAttribute("height"));
Widht = Convert.ToInt16(Stats.GetAttribute("width"));
int CountBack = Convert.ToInt16(xmlDoc.DocumentElement.SelectSingleNode("//Background").Attributes[0].Value);
//string Str = ;
_Background.SetUpBackGround(Resources.Load<Sprite>("Sprites/Back/" + Type + "/" + UnityEngine.Random.Range(1, CountBack + 1)));
List<Vector2> TreesCoords = new List<Vector2>();
int IndentTree = Convert.ToInt16(xmlDoc.DocumentElement.SelectSingleNode("//Tree").Attributes[0].Value);
BlockGrid = new Block[Height + 2, Widht];
// BlockGrid[0, 30] = new Block();
XmlElement Lvl = xmlDoc.GetElementById("1");
for (int i = -1; i <= Height; i++)
{
for (int x = -Widht / 2; x <= Widht / 2 - 1; x++)
{
Rand = UnityEngine.Random.value;
switch (i)
{
case -1:
if (UnityEngine.Random.value < Convert.ToSingle(xmlDoc.DocumentElement.SelectSingleNode("//Tree").Attributes[1].Value))
{
if (x <= 0)
{
if (TreesCoords.Count > 0)
{
if (TreesCoords[TreesCoords.Count - 1].x + IndentTree <= x)
TreesCoords.Add(new Vector2(x, 1));
}
else
TreesCoords.Add(new Vector2(x, 1));
}
else
{
if (UnityEngine.Random.value < 0.5f)
if (TreesCoords.Count > 0)
{
if (TreesCoords[TreesCoords.Count - 1].x + IndentTree <= x)
TreesCoords.Add(new Vector2(x, 1));
}
else
TreesCoords.Add(new Vector2(x, 1));
}
}
break;
case 0:
Now = Instantiate(Resources.Load("Prefab/GroundUp"), new Vector3(x, -i, 0), Quaternion.identity) as GameObject;
BlockGrid[i, x + 15] = Now.GetComponent<Ground>();
BlockGrid[i, (x + 15)].gameObject.transform.parent = this.gameObject.transform;
break;
default:
if (UnityEngine.Random.value <= Difficalt)
{
if (!BlockGrid[i, x + 15])
{
Now = Instantiate(Resources.Load("Prefab/Ground"), new Vector3(x, -i, 0), Quaternion.identity) as GameObject;
BlockGrid[i, x + 15] = Now.GetComponent<Ground>();
BlockGrid[i, (x + 15)].gameObject.transform.parent = this.gameObject.transform;
}
}
else
{
bool Spawn = false;
XmlNodeList dataList = xmlDoc.GetElementsByTagName("level")[0].ChildNodes;
for (int j = 0; j < dataList.Count; j++)
{
string[] substrings = Regex.Split(dataList[j].Attributes[1].Value, "(-)");
if (i >= Convert.ToInt16(substrings[0]) && i <= Convert.ToInt16(substrings[2]))
{
Rand = UnityEngine.Random.value;
if (Rand <= Convert.ToSingle(dataList[j].Attributes[0].Value) && !BlockGrid[i, x + 15])
{
if (!BlockGrid[i, x + 15])
GenerateResourse(i, x, dataList[j].Attributes[2].Value, dataList[j].Name);
//.........这里部分代码省略.........