public static void Main()
string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<bookstore xmlns=""http://www.contoso.com/books"">
<book genre=""autobiography"" publicationdate=""1981-03-22"" ISBN=""1-861003-11-0"">
<title>The Autobiography of Benjamin Franklin</title>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
<book genre=""novel"" publicationdate=""1967-11-17"" ISBN=""0-201-63361-2"">
<title>The Confidence Man</title>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
<book genre=""philosophy"" publicationdate=""1991-02-15"" ISBN=""1-861001-57-6"">
<title>The Gorgias</title>
XmlDocument xmlDoc = new XmlDocument();
string json = JsonConvert.SerializeXmlNode(xmlDoc);
string xsd = @"<?xml version=""1.0"" encoding=""utf-8""?>
<xs:schema attributeFormDefault=""unqualified"" elementFormDefault=""qualified"" targetNamespace=""http://www.contoso.com/books"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:element name=""bookstore"">
<xs:element maxOccurs=""unbounded"" name=""book"">
<xs:element name=""title"" type=""xs:string"" />
<xs:element name=""author"">
<xs:element minOccurs=""0"" name=""name"" type=""xs:string"" />
<xs:element minOccurs=""0"" name=""first-name"" type=""xs:string"" />
<xs:element minOccurs=""0"" name=""last-name"" type=""xs:string"" />
<xs:element name=""price"" type=""xs:decimal"" />
<xs:attribute name=""genre"" type=""xs:string"" use=""required"" />
<xs:attribute name=""publicationdate"" type=""xs:date"" use=""required"" />
<xs:attribute name=""ISBN"" type=""xs:string"" use=""required"" />
bool isValid = ValidateJsonAgainstXsd(json, xsd);
Console.WriteLine("JSON is not valid according to the XSD.");
Console.WriteLine(isValid);
static bool ValidateJsonAgainstXsd(string json, string xsd)
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(JsonConvert.DeserializeXmlNode(json).OuterXml);
xmlDoc.Schemas.Add("http://www.contoso.com/books", XmlReader.Create(new StringReader(xsd)));
xmlDoc.Validate((sender, e) =>
Console.WriteLine(e.Message);