| 114 | } |
| 115 | |
| 116 | static void test3() |
| 117 | { |
| 118 | const char* s = "<servers>" |
| 119 | "<proc><pid>1200</pid><load>2.5</load></proc>" |
| 120 | "<proc><pid>1300</pid><load>3.5</load></proc>" |
| 121 | "<proc><pid>1400</pid><load>4.5</load></proc>" |
| 122 | "</servers>"; |
| 123 | acl::xml1 xml(s); |
| 124 | |
| 125 | printf("---------------- after parse xml ---------------------\r\n"); |
| 126 | |
| 127 | if (strcmp(s, xml.to_string()) == 0) |
| 128 | { |
| 129 | printf("[%s]\r\n", xml.to_string()); |
| 130 | printf("----OK----\r\n"); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | printf("[%s]\r\n", s); |
| 135 | printf("[%s]\r\n", xml.to_string()); |
| 136 | printf("----Error----\r\n"); |
| 137 | } |
| 138 | |
| 139 | printf("Enter any key to continue ...\r\n"); |
| 140 | getchar(); |
| 141 | |
| 142 | printf("--------------- after delete first pid ------------\r\n"); |
| 143 | |
| 144 | acl::xml_node* first_pid = xml.getFirstElementByTag("pid"); |
| 145 | if (first_pid) |
| 146 | first_pid->detach(); |
| 147 | |
| 148 | printf("[%s]\r\n", xml.to_string()); |
| 149 | |
| 150 | printf("Enter any key to continue ...\r\n"); |
| 151 | getchar(); |
| 152 | |
| 153 | printf("--------------- after delete all load --------------\r\n"); |
| 154 | const std::vector<acl::xml_node*>& loads = |
| 155 | xml.getElementsByTagName("load"); |
| 156 | for (std::vector<acl::xml_node*>::const_iterator cit = loads.begin(); |
| 157 | cit != loads.end(); ++cit) |
| 158 | { |
| 159 | (*cit)->detach(); |
| 160 | } |
| 161 | |
| 162 | printf("[%s]\r\n", xml.to_string()); |
| 163 | |
| 164 | printf("Enter any key to continue ...\r\n"); |
| 165 | getchar(); |
| 166 | } |
| 167 | |
| 168 | int main(void) |
| 169 | { |