Pergunta

I am having a few problems with rapidxml. When I compile my code no start tags are included..any and all help will be greatly appreciated

    int main(){


    xml_document<> doc;
    //xml declaration
    xml_node<>* decl = doc.allocate_node(node_declaration);
    decl->append_attribute(doc.allocate_attribute("version","1.0"));
    decl->append_attribute(doc.allocate_attribute("encoding", "utf-8"));
        doc.append_node(decl);
     // root node
        xml_node<>* root = doc.allocate_node(node_element, "root");
        root->append_attribute(doc.allocate_attribute(""));
                    doc.append_node(root);
                // child/sibling node
        xml_node<>* sibling0 = doc.allocate_node(node_element, "old");
        root->append_node(sibling0);
        xml_node<>* sibling = doc.allocate_node(node_element,"boy");
        root->append_node(sibling );
                 std::string xmlstring;
        print(back_inserter(xmlstring), doc);
        cout << xmlstring << endl;}
Foi útil?

Solução

Apart from the necessary #includes, and missing using namespace rapidxml; your code compiles and runs fine for me.

xmlstring contains this:

<?xml version="1.0" encoding="utf-8"?>
<root ="">
    <old/>
    <boy/>
</root>

Because old and boy have no content, they use xml empty element tags, <tagname/>rather than start and end pairs like <tagname></tagname>

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top