Game Development Reference
In-Depth Information
static void Main(string[] args)
{
if (args.GetLength(0) == 0)
{
Console.WriteLine("Usage XmlValidate document.dae");
return;
}
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(
" http :// www . w3 . org / XML /1998/ namespace " ,
" http :// www . w3 . org /2001/ xml . xsd " );
settings.Schemas.Add(
" http :// www . collada . org /2005/11/COLLADASchema " ,
" http :// www . khronos . org / files / collada_schema_1_4 " );
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
try
{
XmlReader reader = XmlReader.Create(args[0], settings);
while (reader.Read())
{
// Can add code here to process the content.
}
reader.Close();
}
catch (System.IO.FileNotFoundException e)
{
Console.WriteLine("\n[File Not Found] {0}", args[0]);
return;
}
catch (System.Xml.XmlException e)
{
Console.WriteLine("[XML error] {0}", e.Message);
isValid = false;
}
catch (System.Xml.Schema.XmlSchemaValidationException e)
{
Console.WriteLine("[Validation error] {0}", e.Message);
isValid = false;
}
// Check whether the document is valid or invalid.
if (isValid)
Console.WriteLine("\nDocument is valid");
else
Console.WriteLine("\nDocument is invalid");
}
}
}
}
Listing 9.1. An XML COLLADA validation tool in C#.
Search WWH ::




Custom Search