我正在用XSD编写XML验证器.
以下是我所做的,但当验证器到达该行时,while (list.Read())它会给我错误
没有Unicode字节顺序标记.无法切换到Unicode.
任何人都可以帮我解决这个问题吗?
public class Validator
{
public void Validate(string xmlString)
{
Boolean bRet = true;
string xmlPath = @"C:\x.xml";
string xsdPath = @"C:\general.xsd";
XmlReaderSettings Settings = new XmlReaderSettings();
Settings.Schemas.Add("", xsdPath);
Settings.ValidationType = ValidationType.Schema;
Settings.ValidationEventHandler +=
new ValidationEventHandler(SettingsValidationEventHandler);
XmlReader list = XmlReader.Create(xmlPath, Settings);
//StringBuilder output = new StringBuilder();
while (list.Read())
{
}
//File.WriteAllText(@"D:\Output.xml", output.ToString());
}
static void SettingsValidationEventHandler(object sender,
ValidationEventArgs e)
{
if (e.Severity == XmlSeverityType.Warning)
{
MessageBox.Show( "WARNING: ");
MessageBox.Show(e.Message);
}
else if (e.Severity == …Run Code Online (Sandbox Code Playgroud)