C # Use the xsd file to verify whether the XML format is correct,
C # Use the xsd file to verify whether the XML format is correct
Core sample code:
C # code
- // Create an xmlDocument
- XmlDocument doc = new XmlDocument ();
- // Create a claim segment, as shown in <? Xml version = "1.0" encoding = "UTF-8"?>
- Doc. AppendChild (doc. CreateXmlDeclaration ("1.0", "UTF-8", null ));
- // Create a root node KYTResults
- XmlElement results = doc. CreateElement ("KYTResults ");
- // Create ResultsStatus
- XmlNode resultsStatus = doc. CreateElement ("ResultsStatus ");
- // Create a Level
- XmlElement element = doc. CreateElement ("Level ");
- Element. InnerText = status? "0": "1 ";
- ResultsStatus. AppendChild (element );
- // Create Description
- Element = doc. CreateElement ("Description ");
- Element. InnerText = msg;
- ResultsStatus. AppendChild (element );
- // Create a PassKey. If the user fails to log on, an empty character will be loaded.
- Element = doc. CreateElement ("PassKey ");
- Element. InnerText = key;
- ResultsStatus. AppendChild (element );
- Results. AppendChild (resultsStatus );
- // END creates ResultsStatus
- // Create a DataList data set
- If (status)
- {
- Results. AppendChild (dataList );
- }
- // END creates a root node KYTResults
- Doc. AppendChild (results );
- String path = Server. MapPath ("/ws/xsd/ReceiveReturn. xsd ");
- // Verify that the xml format has passed xsd Verification
- String error = "";
- // Declare XmlSchema
- XmlSchemaSet schemas = new XmlSchemaSet ();
- Schemas. Add ("", XmlReader. Create (path ));
- // Declare the event handling method
- ValidationEventHandler eventHandler = new ValidationEventHandler (delegate (object sender, ValidationEventArgs e ){
- Switch (e. Severity)
- {
- Case XmlSeverityType. Error:
- Error + = e. Message;
- Break;
- Case XmlSeverityType. Warning:
- Break;
- }
- });
- Doc. Schemas = schemas;
- // Verify xml
- Doc. Validate (eventHandler );
- // Check whether there is any exception. If the format is incorrect, it will be thrown out.
- If (! "". Equals (error ))
- {
- Throw new Exception (error );
- }
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.