3, pugixml change the node name, attribute name, attribute value

    :: xml_document doc Pugi;
     IF (! doc.load_string ( " <Node ID = '123'> text </ Node> " , Pugi :: parse_default | Pugi :: parse_comments)) return - . 1 ; // XML content 
    doc .print (cout); // print original content

    // 节点Node 
    Pugi :: Xml_node Node = Doc.Child ( " Node " );

    // modify node name, node-> notnode 
    std :: cout << node.set_name ( " notnode " );
    std::cout << ", new node name: " << node.name() << std::endl;

    // 属性id
    pugi::xml_attribute attr = node.attribute("id");

    // 修改属性名、值,id->key,123->345
    std::cout << attr.set_name("key") << ", " << attr.set_value("345");
    std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl;

    // modify the id attribute value again, 345-> 1.234 
    attr.set_value ( 1.234 );
    std::cout << "new attribute value: " << attr.value() << std::endl;

    // Modify the id attribute value again, 1.234-> to true 
    attr = to true ; // Boolean value 
    std :: cout << " Final attribute value: " << attr.value () << std :: endl;

    Doc.print (std :: cout); // print results

 

Guess you like

Origin www.cnblogs.com/xixixing/p/12123254.html