XML exercises (1)

Source: Internet
Author: User

Understanding: XML has several verification methods, DTD and mode. That is, the pattern is used to verify whether the XML meets the requirements.

081223

  1. // Write
  2. // Dataset DS = oledbhelper. executeds ("select * From userinfo ");
  3. // Ds. writexml (server. mappath (@"~ /Xmlstudy/") +" 123.xml ");
  4. // Read
  5. Dataset DS = new dataset ();
  6. DS. readxml (server. mappath (@"~ /Xmlstudy/") +" 123.xml ");

081222

Boyi helps implement a small function

  1. Xmldocument Doc = new xmldocument ();
  2. Doc. Load (@ "../test. xml"); // load the XML document
  3. Xmlnode root = Doc. documentelement; // get the document root node
  4. If (root. haschildnodes)
  5. {
  6. Xmlnode ELEM = Doc. createnode (xmlnodetype. element, "category", null );
  7. String XPath = "Descendant: level-1 node [/root node/level-1 node [name = 'tree']";
  8. Xmlnodelist xnlist = Doc. selectnodes (XPath );
  9. Foreach (xmlnode item in xnlist)
  10. {
  11. ELEM. appendchild (item );
  12. }
  13. Root. prependchild (ELEM );
  14. Doc. Save (@ "../test. xml ");
  15. Console. Write (Doc. innerxml );
  16. }
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Root node>
  3. <Category>
  4. <Level 1 node id = "001">
  5. <Name> tree </Name>
  6. <Sex> male </sex>
  7. </Primary node>
  8. <Level 1 node id = "002">
  9. <Name> Boyi </Name>
  10. <Sex> female </sex>
  11. </Primary node>
  12. </Category>
  13. </Root node>
  14. <! -- Modified data
  15. <Root node>
  16. <Level 1 node id = "001">
  17. <Name> tree </Name>
  18. <Sex> male </sex>
  19. </Primary node>
  20. <Level 1 node id = "002">
  21. <Name> Boyi </Name>
  22. <Sex> female </sex>
  23. </Primary node>
  24. </Root node>
  25. -->

End

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.