blob: afd62864dce7385ed31a4057fd1d1d854ee0add1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (c) Microsoft Corporation. All rights reserved.
//
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.XPath;
namespace Microsoft.Ddue.Tools {
public class ValidateComponent : BuildComponent {
private XmlSchemaSet schemas = new XmlSchemaSet();
public ValidateComponent (BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) {
XPathNodeIterator schema_nodes = configuration.Select("schema");
foreach (XPathNavigator schema_node in schema_nodes) {
string file = schema_node.GetAttribute("file", String.Empty);
schemas.Add(null, file);
}
}
public override void Apply (XmlDocument document, string key) {
// set the validate schema
document.Schemas = schemas;
// create a validation handler
ValidationEventHandler handler = new ValidationEventHandler(LogValidationError);
// validate the document
document.Validate(handler);
}
private void LogValidationError (Object o, ValidationEventArgs e) {
string message = String.Format("ValidationError: {0}", e.Message);
WriteMessage(MessageLevel.Warn, message);
}
}
}
|