2017-04-19 2 views
0

Schematron.net nuget 패키지를 사용하고 있으며 결과를 구조화 된 형식으로 처리 할 수 ​​있도록 Validate 호출 결과를 얻을 수 있는지 알고 싶습니다. 내 기존 솔루션은 try catch 블록을 사용하며 어설 션 오류는 모두 오류 메시지로 예외 내에서 메시지로 반환됩니다. 이 정보를 XML로 가져 오는 방법이 있습니까? 나는 비슷한 질문을하는 post을 보았지만 그 대답은 Schematron.net 구현을 언급하지 않는다.Schematron.net 구조화 된 오류보고

내 코드는 다음과 같습니다

try 
{ 
    var bookValidator = new Validator(); 
    bookValidator.AddSchema("book.xsd"); 
    bookValidator.Validate("book.xml"); 
} 
catch (Exception ex) 
{ 
    Console.WriteLine(ex.Message); 
} 

답변

0

그것은 실제로 매우 간단합니다.

try 
{ 
    //OutputFormatting is a public enum from the Schematron library. Valid values include boolean, default, Log, simple and XML. 
    OutputFormatting format = OutputFormatting.XML; 
    var bookValidator = new Validator(format); 
    bookValidator.AddSchema("book.xsd"); 
    bookValidator.Validate("book.xml"); 
} 
catch (Exception ex) 
{ 
    //ex.Message will now be in XML format and can be processed however I want! 
    Console.WriteLine(ex.Message); 
} 

을 그리고 구조화 된 결과가있다 : 난 그냥 검사기 생성자에 OutputFormatting의 적절한 열거를 통과하는 날과 같이 예외에서 메시지의 형식을 제어 할 수 있음을 깨달았다. 나는 그것이 누군가에게 도움이되기를 희망한다.