Hello,
I have been running the C# code below in Visual Studio 2012 and .NET version 4.5 (Windows 7 - 32 bit).
It basically opens an XSD schema file and an XML file that needs to be validated and parsed later.
It works fine in visual studio and also the W3C validator shows that the both XSD Schema file and XML file are ok and valid.
However when moving to Unity3D WebPlayer platform, by creating a script attached to a gameobject and executing the code in the Start() method, I get all sort of XML schema errors (I do not report them since they vary if I change the XML input file).
My guess is that it could be a file encoding issue with Unity or .NET/mono compatibility issue with the System.XML packages.
Any suggestion? Does any of you know of to solve this?
Any help or suggestion is really appreciated.
Here you have the code snippet:
try
{
// Creates settings for the XmlReader
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
settings.ValidationType = ValidationType.Schema;
// Creates the event handler for the validation process
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
settings.ValidationEventHandler += eventHandler;
// Adding the Schema definition to XMLReader settings
Debug.Log("Adding Schema definition to XMLReader settings");
settings.Schemas.Add("http://cadia.ru.is/MySchemaSpecification", "MySchemaSpecification.xsd");
// Creates the XmlReader and assigns the settings
XmlReader MyXMLInputReader = XmlReader.Create("MyXMLFile.xml", settings);
// Creates a new XML document and loads the data using the XMLReader
Debug.Log("Loading XML doc");
XmlDocument MyXMLInputDoc = new XmlDocument();
MyXMLInputDoc .Load(MyXMLInputReader );
// Validates the XML file
MyXMLInputDoc .Validate(eventHandler);
Debug.Log("Validation finished");
}
catch (Exception ex)
{
Debug.Log(ex.Message);
}