Validate base64 zip xml file by xsd



I need validate base64 zip xml file. Zipped by SharpZipLib.Zip. I create test code for validation, but when run reader.Read() method I have error - System.Xml.XmlException, '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.


string xsdPath = @"@"c:\Test.xsd"; byte[] byteArray = Convert.FromBase64String(Resources.TestBase64);



using (Stream memInput = new MemoryStream(byteArray))
using (ZipInputStream input = new ZipInputStream(memInput))
{
ZipEntry entry = input.GetNextEntry();

byte[] newBytes = new byte[entry.Size];

XmlSchemaSet sc = new XmlSchemaSet();
StringReader stringReader = new StringReader(File.ReadAllText(xsdPath, Encoding.Default));

// Add the schema to the collection.
sc.Add(null, new XmlTextReader(stringReader));

// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.CheckCharacters = false;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);

MemoryStream streamXml = new MemoryStream(newBytes);
streamXml.Position = 0;
StreamReader readerXml = new StreamReader(streamXml, Encoding.UTF8);

// Create the XmlReader object.
XmlReader reader = XmlReader.Create(readerXml, settings);

// Parse the file.
while (reader.Read())
{


}
}

private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
var result = string.Format("Validation Error: {0} -- {1}", e.Message, e.Exception.LineNumber);
}

No comments:

Post a Comment