Now that we have understood the AddCategories method, let us now take a look at the helper methods used by the AddCategories method. First, let's look at the ValidateXML method. As mentioned earlier, this method is responsible for ensuring that the added CategoriesXML data complies with the predefined XML schema in Categories.xsd.
privateboolValidateXml(stringxml)
{
boolvalidXml=false;
//LoadtheXMLdataintomemory
XmlValidatingReadervalReader=new
XmlValidatingReader(xml,XmlNodeType.Document,null);
valReader.Schemas.Add(null,Server.MapPath("Categories.xsd"));
valReader.ValidationType=ValidationType.Schema;
valReader.ValidationEventHandler+=new
ValidationEventHandler(ValidationHandler);
//LoopthroughtheXMLfile
while(valReader.Read())
{}
if(builder.Length>0)
validXml=false;
else
validXml=true;
valReader.Close();
returnvalidXml;
}