| 151 | } |
| 152 | |
| 153 | void Element::save(std::ostream& _stream, size_t _level) |
| 154 | { |
| 155 | // сначала табуляции намутим |
| 156 | for (size_t tab = 0; tab < _level; ++tab) |
| 157 | _stream << " "; |
| 158 | |
| 159 | // теперь заголовок тега |
| 160 | if (mType == ElementType::Declaration) |
| 161 | _stream << "<?"; |
| 162 | else if (mType == ElementType::Comment) |
| 163 | _stream << "<!--"; |
| 164 | else |
| 165 | _stream << "<"; |
| 166 | |
| 167 | _stream << mName; |
| 168 | |
| 169 | for (auto& attribute : mAttributes) |
| 170 | { |
| 171 | _stream << " " << attribute.first << "=\"" << utility::convert_to_xml(attribute.second) << "\""; |
| 172 | } |
| 173 | |
| 174 | bool empty = mChildren.empty(); |
| 175 | // если детей нет то закрываем |
| 176 | if (empty && mContent.empty()) |
| 177 | { |
| 178 | if (mType == ElementType::Declaration) |
| 179 | _stream << "?>\n"; |
| 180 | else if (mType == ElementType::Comment) |
| 181 | _stream << "-->\n"; |
| 182 | else |
| 183 | _stream << "/>\n"; |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | _stream << ">"; |
| 188 | if (!empty) |
| 189 | _stream << "\n"; |
| 190 | // если есть тело то сначало оно |
| 191 | if (!mContent.empty()) |
| 192 | { |
| 193 | if (!empty) |
| 194 | { |
| 195 | for (size_t tab = 0; tab <= _level; ++tab) |
| 196 | _stream << " "; |
| 197 | } |
| 198 | _stream << utility::convert_to_xml(mContent); |
| 199 | |
| 200 | if (!empty) |
| 201 | _stream << "\n"; |
| 202 | } |
| 203 | // save child items |
| 204 | for (const auto& child : mChildren) |
| 205 | { |
| 206 | child->save(_stream, _level + 1); |
| 207 | } |
| 208 | |
| 209 | if (!empty) |
| 210 | { |
nothing calls this directly
no test coverage detected