Phpxml operation class (custom)

Source: Internet
Author: User
Phpxml operation class (custom)

  1. /**

  2. Php xml operations
  3. Link: http://bbs.it-home.org
  4. */
  5. Class requirelog
  6. {
  7. Protected static $ requirelog;

  8. // Get ready for xml, if xml is not found, create xml

  9. Static function _ initializeLog ()
  10. {
  11. If (file_exists ('requirelog. XML '))
  12. {

  13. Self: $ requirelog = DOMDocument: load ('requirelog. XML ');

  14. }
  15. Else
  16. {
  17. Self: $ requirelog = new DOMDocument ('1. 0', 'ISO-8859-1 ');
  18. Self: $ requirelog-> loadXML (' ');
  19. Self: $ requirelog-> save ('requirelog. XML ');
  20. }
  21. }
  22. // Obtain all nodes whose finish field is all 0
  23. Public static function get_entrys ()
  24. {
  25. Self: _ initializeLog ();
  26. $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
  27. $ Entry_arrays = array ();
  28. Foreach ($ entrys as $ entry)
  29. {
  30. If ($ entry-> getElementsByTagName ('finish ')-> item (0)-> nodeValue = 0)
  31. {
  32. $ Entry_array = array ();
  33. $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
  34. $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
  35. $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
  36. $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
  37. $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
  38. $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
  39. $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;

  40. $ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;

  41. $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
  42. $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
  43. $ Entry_arrays [] = $ entry_array;
  44. }
  45. }
  46. Return $ entry_arrays;
  47. }
  48. // Obtain all nodes
  49. Public static function get_count_entrys ()
  50. {
  51. Self: _ initializeLog ();
  52. $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
  53. $ Entry_arrays = array ();
  54. Foreach ($ entrys as $ entry)
  55. {

  56. $ Entry_array = array ();

  57. $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
  58. $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
  59. $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
  60. $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
  61. $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
  62. $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
  63. $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;

  64. $ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;

  65. $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
  66. $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
  67. $ Entry_arrays [] = $ entry_array;

  68. }

  69. Return $ entry_arrays;
  70. }

  71. // Obtain the node by ID

  72. Public static function get_entry ($ id)
  73. {
  74. Self: _ initializeLog ();
  75. $ Count = count (self: get_count_entrys ());
  76. If ($ count> 0)
  77. {
  78. $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
  79. Foreach ($ entrys as $ entry)
  80. {
  81. If ($ id = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue)
  82. {
  83. $ Entry_array = array ();
  84. $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
  85. $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
  86. $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
  87. $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
  88. $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
  89. $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
  90. $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;

  91. $ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;

  92. $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
  93. $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
  94. Return $ entry_array;
  95. }
  96. }
  97. }
  98. Else
  99. Return null;
  100. }

  101. // After the user request is executed, change the finsh field

  102. Public static function do_finsh ($ id)
  103. {
  104. Self: _ initializeLog ();
  105. $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
  106. $ Entry_arrays = array ();
  107. Foreach ($ entrys as $ entry)
  108. {
  109. If ($ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue = $ id)
  110. {
  111. $ Entry-> getElementsByTagName ('finish ')-> item (0)-> nodeValue = 1;
  112. }
  113. }

  114. Self: $ requirelog-> save ('requirelog. XML ');

  115. }

  116. // Add a new node. $ operator is the operator, $ byoperator is the object to be operated, $ parameters1, 2 and 3 are extensible parameters, $ type is the type, and $ module is the affected module.

  117. Static function add_entry ($ operator, $ byoperator, $ parameters1, $ parameters2, $ parameters3, $ type, $ module)
  118. {
  119. // $ Contents = self: $ restlog-> getElementsByTagName ('contents ');

  120. Self: _ initializeLog ();

  121. $ Count = count (self: get_count_entrys ());

  122. $ Entry = self ::$ requirelog-> createElement ('entry ');

  123. $ Id = self ::$ requirelog-> createElement ('id ');

  124. $ Idvalue = self: $ requirelog-> createTextNode ($ count + 1 );
  125. $ Id-> appendChild ($ idvalue );

  126. $ Time = self: $ requirelog-> createElement ('time ');

  127. $ Timevalue = self ::$ requirelog-> createTextNode (date ("Y-m-d H: I: s", time ()));
  128. $ Time-> appendChild ($ timevalue );

  129. $ Op = self ::$ requirelog-> createElement ('operator ');

  130. $ Opvalue = self: $ requirelog-> createTextNode ($ operator );
  131. $ Op-> appendChild ($ opvalue );

  132. $ Bop = self ::$ requirelog-> createElement ('byoperator ');

  133. $ Bopvalue = self: $ requirelog-> createTextNode ($ byoperator );
  134. $ Bop-> appendChild ($ bopvalue );

  135. $ Ps1 = self: $ requirelog-> createElement ('parameters1 ');

  136. $ Ps1value = self: $ requirelog-> createTextNode ($ parameters1 );
  137. $ Ps1-> appendChild ($ ps1value );

  138. $ Ps2 = self: $ requirelog-> createElement ('parameters2 ');

  139. $ Ps2value = self: $ requirelog-> createTextNode ($ parameters2 );
  140. $ Ps2-> appendChild ($ ps2value );

  141. $ Ps3 = self ::$ requirelog-> createElement ('parameters3 ');

  142. $ Ps3value = self: $ requirelog-> createTextNode ($ parameters3 );
  143. $ Ps3-> appendChild ($ ps3value );

  144. $ Tp = self ::$ requirelog-> createElement ('type ');
  145. $ Tpvalue = self: $ requirelog-> createTextNode ($ type );
  146. $ Tp-> appendChild ($ tpvalue );

  147. $ Md = self ::$ requirelog-> createElement ('module ');

  148. $ Mdvalue = self: $ requirelog-> createTextNode ($ module );
  149. $ Md-> appendChild ($ mdvalue );

  150. $ Fi = self ::$ requirelog-> createElement ('finish ');

  151. $ Fivalue = self: $ requirelog-> createTextNode (0 );
  152. $ Fi-> appendChild ($ fivalue );

  153. $ Entry-> appendChild ($ id );

  154. $ Entry-> appendChild ($ time );
  155. $ Entry-> appendChild ($ op );
  156. $ Entry-> appendChild ($ bop );
  157. $ Entry-> appendChild ($ ps1 );
  158. $ Entry-> appendChild ($ ps2 );
  159. $ Entry-> appendChild ($ ps3 );
  160. $ Entry-> appendChild ($ tp );
  161. $ Entry-> appendChild ($ md );
  162. $ Entry-> appendChild ($ fi );

  163. Self: $ requirelog-> documentElement-> appendChild ($ entry );

  164. Self: $ requirelog-> save ('requirelog. XML ');

  165. Return 1;

  166. }
  167. }
  168. ?>

2. the requirelog. xml file is in the following format:

  1. 1
  2. 16:56:33
  3. Peng. zhou
  4. Zxcxzcxzczxcxz
  5. Cxzcxzc
  6. Add_group
  7. Cn_group
  8. 1
  9. 2
  10. 16:56:53
  11. Peng. zhou
  12. Sales
  13. Add_member
  14. Mail_group
  15. 1

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.