Validation process using OpenXML #29
Unanswered
kushalKPMS
asked this question in
Q&A
Replies: 1 comment
-
Hi @kushalKPMS, The Validator returns using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Validation;
static List<ValidationErrorInfo> GetValidationErrorInfos(string path)
{
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(path, false))
{
List<ValidationErrorInfo> errorsList = new List<ValidationErrorInfo>();
try
{
OpenXmlValidator validator = new OpenXmlValidator();
IEnumerable<ValidationErrorInfo> errors = validator.Validate(wordprocessingDocument);
int count = 0;
foreach (ValidationErrorInfo error in errors)
{
count++;
Console.WriteLine("Error " + count);
Console.WriteLine("Description: " + error.Description);
Console.WriteLine("ErrorType: " + error.ErrorType);
Console.WriteLine("Node: " + error.Node);
Console.WriteLine("Path: " + error.Path.XPath);
Console.WriteLine("Part: " + error.Part.Uri);
Console.WriteLine("-------------------------------------------");
errorsList.Add(error);
}
Console.WriteLine("count={0}", count);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return errorsList;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@mikeebowen I wanted to know how exactly are you validating document using open xml. Seems like the validation process i follow seems to throw a lot of errors which are not necessarily errors, but your extension is always on point when it comes to validating.
Ill share my code below of how im performing validation:
Beta Was this translation helpful? Give feedback.
All reactions