root.insert_child_before("Level4", root.first_child())
'u kullanabilirsiniz. Bununla birlikte, her çocuk için farklı bir etiket adının olması alışılmadık bir durumdur. Daha yaygın bir format, çocukların hepsine aynı isimle sahip olmak ve onları birbirinden ayırmak için öznitelikler koymak olacaktır.
bu nasıl yapılabileceği bir örnek:
int main()
{
pugi::xml_document doc;
pugi::xml_node root = doc.append_child("levels");
root.append_child("level").append_attribute("id").set_value("L01");
root.last_child().append_child("description").text().set("Some L01 stuff");
root.append_child("level").append_attribute("id").set_value("L02");
root.last_child().append_child("description").text().set("Some L02 stuff");
// now insert one before the first child
root.insert_child_before("level", root.first_child()).append_attribute("id").set_value("L00");
root.first_child().append_child("description").text().set("Some L00 stuff");
doc.print(std::cout);
}
Çıktı:
<levels>
<level id="L00">
<description>Some L00 stuff</description>
</level>
<level id="L01">
<description>Some L01 stuff</description>
</level>
<level id="L02">
<description>Some L02 stuff</description>
</level>
</levels>