function function: The document is detected according to the schema of the existing document XML
Parameter meaning: Strarchxmlfilepath (document XML file path)
public static bool Checkarchxmlcontent (string strarchxmlfilepath, out string strerrormsg)
{
BOOL Bresult = true;
Strerrormsg = "";
Try
{
Initialize error message
M_strerrormsg = "";
String Strxsdfilepath = "Example.xsd"; XSD Schema document
Constructing the schema schema cache
XmlSchemaSet xssarchcontent = new XmlSchemaSet ();
Add a schema file, preceded by a namespace, is not empty
Xssarchcontent.add ("", Strxsdfilepath);
Define how the document mode is used
XmlReaderSettings xrsarchcontent = new XmlReaderSettings ();
Xrsarchcontent.validationtype = ValidationType.Schema;
Correlation validation Reader and schema collection
Xrsarchcontent.schemas = xssarchcontent;
To add an event handler when an error occurs
Xrsarchcontent.validationeventhandler + = new ValidationEventHandler (dealerror);
Use the latest way to build a reader that can be validated and construct a validation reader
XmlReader xrarchcontent = xmlreader.create (Strarchxmlfilepath, xrsarchcontent);
Cyclic detection of all document nodes
while (Xrarchcontent.read ())
{
}
Determine if a node has syntax errors
if (m_strerrormsg! = "")
{
Bresult = false;
Strerrormsg = m_strerrormsg;
}
}
catch (Exception e)
{
Strerrormsg = E.message.tostring ();
Bresult = false;
}
return bresult;
}
function function: Error handler
public static void Dealerror (object sender, ValidationEventArgs args)
{
Working with Content
M_strerrormsg + = args. Message.tostring () + "/r/n/r/n";
}