C # Use the xsd file to verify whether the XML format is correct,

Source: Internet
Author: User

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  
  1. // Create an xmlDocument
  2. XmlDocument doc = new XmlDocument ();
  3. // Create a claim segment, as shown in <? Xml version = "1.0" encoding = "UTF-8"?>
  4. Doc. AppendChild (doc. CreateXmlDeclaration ("1.0", "UTF-8", null ));
  5. // Create a root node KYTResults
  6. XmlElement results = doc. CreateElement ("KYTResults ");
  7. // Create ResultsStatus
  8. XmlNode resultsStatus = doc. CreateElement ("ResultsStatus ");
  9. // Create a Level
  10. XmlElement element = doc. CreateElement ("Level ");
  11. Element. InnerText = status? "0": "1 ";
  12. ResultsStatus. AppendChild (element );
  13. // Create Description
  14. Element = doc. CreateElement ("Description ");
  15. Element. InnerText = msg;
  16. ResultsStatus. AppendChild (element );
  17. // Create a PassKey. If the user fails to log on, an empty character will be loaded.
  18. Element = doc. CreateElement ("PassKey ");
  19. Element. InnerText = key;
  20. ResultsStatus. AppendChild (element );
  21. Results. AppendChild (resultsStatus );
  22. // END creates ResultsStatus
  23. // Create a DataList data set
  24. If (status)
  25. {
  26. Results. AppendChild (dataList );
  27. }
  28. // END creates a root node KYTResults
  29. Doc. AppendChild (results );
  30. String path = Server. MapPath ("/ws/xsd/ReceiveReturn. xsd ");
  31. // Verify that the xml format has passed xsd Verification
  32. String error = "";
  33. // Declare XmlSchema
  34. XmlSchemaSet schemas = new XmlSchemaSet ();
  35. Schemas. Add ("", XmlReader. Create (path ));
  36. // Declare the event handling method
  37. ValidationEventHandler eventHandler = new ValidationEventHandler (delegate (object sender, ValidationEventArgs e ){
  38. Switch (e. Severity)
  39. {
  40. Case XmlSeverityType. Error:
  41. Error + = e. Message;
  42. Break;
  43. Case XmlSeverityType. Warning:
  44. Break;
  45. }
  46. });
  47. Doc. Schemas = schemas;
  48. // Verify xml
  49. Doc. Validate (eventHandler );
  50. // Check whether there is any exception. If the format is incorrect, it will be thrown out.
  51. If (! "". Equals (error ))
  52. {
  53. Throw new Exception (error );
  54. }

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.