既然我们已经了解了AddCategories方法,现在就让我们来看看AddCategories方法所用到的助手方法。首先,我们看看ValidateXML方法。像前面所提到的那样,该方法负责确保被添加的CategoriesXML数据遵从Categories.xsd中所预先定义好的XML模式。
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;
}