| 569 | |
| 570 | |
| 571 | inline XMLElement * insert_next_element (XMLElement * sibling, const std::string & name, const attribute_list_t & attributes = {}, const std::string & text = ""s) |
| 572 | { |
| 573 | if (!sibling) |
| 574 | throw XmlException ("null element"s); |
| 575 | |
| 576 | auto parent = sibling -> Parent(); |
| 577 | if (!parent) |
| 578 | throw XmlException ("orphaned element"s); |
| 579 | |
| 580 | XMLElement * element = parent -> GetDocument() -> NewElement (name .c_str()); |
| 581 | if (!element) |
| 582 | throw XmlException ("unable to create element"s); |
| 583 | |
| 584 | auto inserted = parent -> InsertAfterChild (sibling, element) != nullptr; |
| 585 | // todo: this block is identical to append_element(), make common code |
| 586 | if (inserted) |
| 587 | { |
| 588 | for (auto const & attr : attributes) |
| 589 | element -> SetAttribute (attr .Name() .c_str(), attr .Value() .c_str()); |
| 590 | if (!text .empty()) |
| 591 | element -> SetText (text .c_str()); |
| 592 | return element; |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | parent -> GetDocument() -> DeleteNode (element); |
| 597 | throw XmlException ("unable to insert element"s); |
| 598 | } |
| 599 | // always returns valid XMLElement on success, failures are exceptions |
| 600 | } |
| 601 | } |
| 602 | } |
nothing calls this directly
no test coverage detected