XML Schema Validation Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ValidationCallBack(object sender, ValidationEventArgs e) | |
{ | |
//์ ํจ์ฑ ๊ฒ์ฌ ์๋ฐ์ ๋ฐ์๋๋ ์ด๋ฒคํธ | |
MessageBox.Show(e.Message); | |
} | |
private void ValidationCh_Click(object sender, EventArgs e) | |
{ | |
string path = @"C:\Book.xml"; | |
XmlReaderSettings xs = new XmlReaderSettings(); | |
xs.ValidationType = ValidationType.Schema; | |
//ValidationType : DTD์ Schema ์ค์์ ์ ํ | |
xs.Schemas.Add("http://www.contoso.com/books", @"C:\Books.xsd"); | |
//Validation ์ ๊ธฐ์ค์ด ๋๋ ์คํค๋ง ์ง์ | |
xs.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings; | |
//Option : validation์ ์ ๋ ์ฒดํฌ | |
xs.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); | |
//Validation Check์, ์๋ฐํ๋ ๊ฒฝ์ฐ ๋ฐ์ํ๋ ์ด๋ฒคํธ ์ง์ | |
XmlReader xmlreader = XmlReader.Create(path, xs); | |
while (xmlreader.Read()) | |
{ | |
//๋ฌธ์์ฒ๋ฆฌ | |
} | |
xmlreader.Close(); | |
} | |