本文整理汇总了C#中XmlData.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# XmlData.Validate方法的具体用法?C# XmlData.Validate怎么用?C# XmlData.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlData
的用法示例。
在下文中一共展示了XmlData.Validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTilesetData
TiledTileset LoadTilesetData( XElement node, TiledTileset tileset )
{
if( node.Name != "tileset" )
{
Log.Editor.WriteError("Cannot load tileset data! (Element should be <tileset>, not <{0}>)", node.Name);
return null;
}
if( tileset == null )
{
Log.Editor.WriteError("Cannot load tileset data! (Tileset is NULL)");
return null;
}
// Read attributes
foreach( var attribute in node.Attributes() )
{
switch( attribute.Name.LocalName )
{
case "firstgid":
tileset.FirstGID = int.Parse(attribute.Value, System.Globalization.NumberStyles.Integer);
break;
case "name":
tileset.Name = attribute.Value;
break;
case "tilewidth":
tileset.TileW = int.Parse(attribute.Value, System.Globalization.NumberStyles.Integer);
break;
case "tileheight":
tileset.TileH = int.Parse(attribute.Value, System.Globalization.NumberStyles.Integer);
break;
case "tilecount":
tileset.TileCount = int.Parse(attribute.Value, System.Globalization.NumberStyles.Integer);
break;
// Tilemap is using an external tileset file; go recursive!
case "source":
using( TextReader txt = new StreamReader(FileOp.Open(@"Source\Media\"+attribute.Value, FileAccessMode.Read) ) )
{
var xml = new XmlData();
var data = txt.ReadToEnd();
xml.SetData(data, data.Length, Encoding.Unicode);
xml.Validate(); // Not sure if this is necessary
// Data is valid
if( xml.IsValid )
return LoadTilesetData(xml.XmlDocument.Root, tileset);
Log.Editor.WriteError("Unable to load external tileset!");
return null;
}
default:
Log.Editor.WriteWarning("Attribute {0} not supported in tilesets.", attribute.Name);
break;
}
}
foreach( var xelem in node.Elements() )
{
var element = (XElement)xelem;
switch( element.Name.LocalName )
{
case "properties":
tileset.LoadProperties( element );
break;
case "tileoffset":
tileset.LoadOffset( element );
break;
case "image":
tileset.LoadImage( element );
break;
case "terraintypes":
tileset.LoadTerrainTypes( element );
break;
case "tile":
tileset.LoadTerrainTile( element );
break;
default:
Log.Editor.WriteWarning("Element {0} not supported in tilesets.", element.Name);
break;
}
}
return tileset;
}