Successfully Validating an XML Element : Schema Validating « XML LINQ « C# / C Sharp

Successfully Validating an XML Element


using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Linq;
using System.IO;
public class MainClass {
    public static void Main() {
        string schema =
          @"<?xml version='1.0' encoding='utf-8'?>
    <xs:schema attributeFormDefault='unqualified' elementFormDefault='qualified'
      <xs:element name='Books'>
         <xs:element maxOccurs='unbounded' name='Book'>
            <xs:element name='FirstName' type='xs:string' />
           <xs:element minOccurs='0' name='MiddleInitial'
                type='xs:string' />
              <xs:element name='LastName' type='xs:string' />
            <xs:attribute name='type' type='xs:string' use='required' />

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.Add("", XmlReader.Create(new StringReader(schema)));



Related examples in the same category

1.Creating an XSD Schema by Inferring Itfrom an XML Document
2.Validating an XML Document with Default Validation Event Handling
3.Validating an XML Document with a Lambda Expression
4.Validating an XML Document
5.XmlSchemaObject represents the root class for the Xml schema