本文整理匯總了C#中System.Xml.XmlDocument.Validate方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.Validate方法的具體用法?C# XmlDocument.Validate怎麽用?C# XmlDocument.Validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.Validate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
internal static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("../../../correctXML.xml");
doc.Schemas.Add("urn:catalogueSchema", "../../../catalogueSchema.xsd");
ValidationEventHandler eventhandler = new ValidationEventHandler(ValidateEventHandler);
doc.Validate(eventhandler);
// I Just delete albums element.
doc.Load("../../../invalidXML.xml");
doc.Validate(eventhandler);
}
示例2: GetCustomersUsingXmlDocument
/// <summary>
/// ¬озвращает список клиентов прочитанный из указанного XML файла с помощью класса XmlDocument
/// </summary>
/// <param name="customersXmlPath">ѕуть к файлу customers.xml</param>
/// <param name="customersXsdPath">ѕуть к файлу customers.xsd</param>
/// <returns>Cписок клиентов</returns>
/// <remarks>ќбратите внимание, что мы всегда возврашаем коллекцию даже если ничего не прочитали из файла</remarks>
/// <exception cref="InvalidCustomerFileException">¬ходной файл не соответствует XML схеме</exception>
public static List<Customer> GetCustomersUsingXmlDocument(string customersXmlPath, string customersXsdPath = null)
{
var customers = new List<Customer>();
var xmlDoc = new XmlDocument();
xmlDoc.Load(customersXmlPath);
if (customersXsdPath != null)
{
xmlDoc.Schemas.Add(CUSTOMERS_NAMESPACE, customersXsdPath);
try
{
xmlDoc.Validate(null);
}
catch (XmlSchemaValidationException ex)
{
throw new InvalidCustomerFileException("Customer.xml has some errors", ex);
}
}
var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("c", CUSTOMERS_NAMESPACE);
XmlNodeList customerNodes = xmlDoc.DocumentElement.SelectNodes("c:Customer", nsmgr);
foreach (XmlElement customerElement in customerNodes)
{
customers.Add(CreateCustomerFromXmlElement(customerElement, nsmgr));
}
return customers;
}
示例3: ReadXml
private XmlDocument ReadXml(string file) {
TextReader xml = new StreamReader(file);
XmlReader xsd = XmlReader.Create(new StreamReader("HVP_Transaction.xsd"));
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, xsd);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new ValidationEventHandler(validationEventHandler);
XmlReader reader = XmlReader.Create(xml, settings);
XmlDocument document = new XmlDocument();
valid = true;
try
{
document.Load(reader);
document.Validate(new ValidationEventHandler(validationEventHandler));
}
finally
{
reader.Close();
xml.Close();
xsd.Close();
}
return valid ? document : null;
}
示例4: Validate
public static bool Validate(XmlDocument document, XmlSchema schema)
{
succes = true;
document.Schemas.Add(schema);
document.Validate(new ValidationEventHandler(ValidationCallBack));
return succes;
}
示例5: Validate
public Boolean Validate()
{
XmlTextReader txtreader = null;
try
{
txtreader = new XmlTextReader(fileName);
XmlDocument doc = new XmlDocument();
doc.Load(txtreader);
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
doc.Validate(eventHandler);
}
catch (IOException e)
{
LogBookController.Instance.addLogLine("Error accessing chapter files. Probably doesn't exist. \n" + e, LogMessageCategories.Error);
return false;
}
catch (XmlException e)
{
LogBookController.Instance.addLogLine("Error inside chapters XML file, trying again.\n" + e, LogMessageCategories.Error);
return false;
}
finally
{
txtreader.Close();
}
return true;
}
示例6: Validate
public Domain.ErrorCode Validate(IXPathNavigable configSectionNode)
{
log.Debug("Validating the configuration");
lock (syncLock)
{
try
{
isValid = true;
//TODO: is there a better way to do this?
var navigator = configSectionNode.CreateNavigator();
var doc = new XmlDocument();
doc.LoadXml(navigator.OuterXml);
doc.Schemas.Add(Schema);
doc.Validate(ValidationCallback);
if (isValid)
{
log.Debug("The configuration is valid");
}
else
{
log.Error("The configuration is invalid");
}
}
catch (XmlException ex)
{
log.Error("An error occurred when validating the configuration", ex);
isValid = false;
}
return isValid ? Domain.ErrorCode.Ok : Domain.ErrorCode.InvalidConfig;
}
}
示例7: ValidaXml
/// <summary>
/// Valida uno stream XML dal tuo schema XSD
/// </summary>
/// <param name = "avviso"></param>
/// <param name = "fileStream">Stream XML</param>
/// <param name = "xsdFilePath">Schema XSD</param>
/// <returns></returns>
public static bool ValidaXml(out string avviso, Stream fileStream, string xsdFilePath)
{
_xmlValido = true;
using (fileStream)
{
try
{
var document = new XmlDocument();
document.PreserveWhitespace = true;
document.Schemas.Add(null, xsdFilePath);
document.Load(fileStream);
document.Validate(ValidationCallBack);
}
catch (Exception ex)
{
avviso = ex.Message;
_xmlValido = false;
return _xmlValido;
}
avviso = _avviso;
return _xmlValido;
}
}
示例8: XmlLoader
/// <summary>
/// Initializes the mission and vilidates the mission file with mission XMLSchema file.
/// </summary>
/// <param name="missionFilePath">The path to the file with mission.</param>
/// <param name="teams">The dictionary which will be filled by Teams (should be empty).</param>
/// <param name="solarSystems">The dictionary which will be filled by SolarSystem. (should be empty).</param>
public XmlLoader(string missionFilePath, Dictionary<string, Team> teams,
List<SolarSystem> solarSystems)
{
loadedMovements = new Dictionary<string, string>();
loadedOccupations = new List<Tuple<List<string>, string, int>>();
loadedFights = new List<Tuple<List<string>, List<string>>>();
teamRealationDict = new Dictionary<Team, List<Team>>();
this.teamDict = teams;
this.solarSystemList = solarSystems;
xml = new XmlDocument();
// Checks the mission XmlSchema
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("", schemaPath);
xml.Load(missionFilePath);
xml.Schemas.Add(schemas);
string msg = "";
xml.Validate((o, err) => {
msg = err.Message;
});
if (msg == "") {
Console.WriteLine("Document is valid");
} else {
throw new XmlLoadException("Document invalid: " + msg);
}
root = xml.DocumentElement;
runtimeCtor = new RunTimeCreator();
}
示例9: ValidategbXML_601
/// <summary>
/// Validate gbxml file against the 6.01 schema XSD
/// </summary>
private void ValidategbXML_601()
{
XmlDocument xml = new XmlDocument();
xml.Load(@"data/TestgbXML.xml");
xml.Schemas.Add(null, @"data/GreenBuildingXML_Ver6.01.xsd");
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
xml.Validate(eventHandler);
}
示例10: Validate
public static void Validate(XmlDocument message)
{
string errMsgs = string.Empty;
message.Validate((sender, args) => { errMsgs += args.Message; });
if (!string.IsNullOrEmpty(errMsgs))
throw new ArgumentOutOfRangeException(errMsgs);
}
示例11: Validate
/// <summary>
/// Validate the given XML against the schema.
/// </summary>
/// <param name="xmlDocument">An <see cref="XmlDocument"/>. The XML to validate.</param>
/// <param name="schemas">An <see cref="XmlSchemaSet"/>. The schema to validate with.</param>
public static void Validate(XmlDocument xmlDocument, XmlSchemaSet schemas)
{
if (xmlDocument == null)
{
throw new ArgumentNullException("xmlDocument");
}
xmlDocument.Schemas = schemas;
xmlDocument.Validate(null);
}
示例12: ValidateXML
private void ValidateXML(XmlDocument inputXmlDocument)
{
inputXmlDocument.Schemas.Add("", new XmlTextReader(new StringReader(Resources.XmlServerReport)));
inputXmlDocument.Validate(
(o, e) =>
{
throw new CruiseControlRepositoryException(
"Invalid XML data. Does not validate against the schema", e.Exception);
});
inputXmlDocument.Schemas = null;
}
示例13: ValidateXML
public void ValidateXML ()
{
XmlReader reader = XmlReader.Create ("MyModels.xml");
XmlDocument document = new XmlDocument ();
document.Schemas.Add ("", "MyModels.xsd");
document.Load (reader);
document.Validate (new
ValidationEventHandler (ValidationEventHandler));
}
示例14: CheckSchemaValidation
/// <summary>
/// Checks the schema validation.
/// </summary>
/// <param name="xml">The XML.</param>
private static void CheckSchemaValidation(string xml)
{
var document = new XmlDocument();
document.Schemas.Add("http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection",
XmlReader.Create("IgniteConfigurationSection.xsd"));
document.Load(new StringReader(xml));
document.Validate(null);
}
示例15: ValidateXML
public void ValidateXML(string xmlPath)
{
string xsdPath = @"Resources\person.xsd";
Console.WriteLine("Validating " + xmlPath);
XmlReader reader = XmlReader.Create(xmlPath);
XmlDocument document = new XmlDocument();
document.Schemas.Add("", xsdPath);
document.Load(reader);
document.Validate(ValidationEventHandler);
}