olaitan temi

olaitan temi

  • NA
  • 8
  • 2.4k

upload xml file to validate xsd file already store in mvc

Sep 23 2015 5:42 AM
already create my controller
 
 
 public ActionResult Index()
{
Validations Validate = new Validations();
string isValidate = Validate.ValidateXMlUsingXSD();
if (isValidate == string.Empty)
isValidate = "xml is well formed according to XSd.";
ViewBag.Validate=isValidate;
return View();
}
]
}
 
and the service code
 
namespace ValidateXmlUsingXsd1.Service
{
public class Validations
{
public string ValidateXMlUsingXSD()
{
try
{
string xmlPath = @"C:\Users\topcrat\Documents\Visual Studio 2013\Projects\ValidateXmlUsingXsd1\ValidateXmlUsingXsd1\XML\XMLFile1.xml";
string xsdPath = @"C:\Users\topcrat\Documents\Visual Studio 2013\Projects\ValidateXmlUsingXsd1\ValidateXmlUsingXsd1\XSD\XMLSchema1.xsd";
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, XmlReader.Create(xsdPath));

XmlReader xmlReader = XmlReader.Create(xmlPath, settings);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
return string.Empty;
}
catch(Exception e )
{
return e.Message;
}
}}
 
i want to be able to upload my xml file via view and validate it against the schema.

Answers (3)