Ejemplo n.º 1
0
void add_to_toc(int level, xml_node<char> *title, xml_attribute<char> *id, bool not_numbered)
{
    char *style_class;
    char *fulltitle = doc.allocate_string(0, title->value_size() + 100);
    if (level == 0)
    {
        style_class = "toc1";
        if (not_numbered)
        {
            sprintf(fulltitle, title->value());
        }
        else
        {
            sprintf(fulltitle, "%i. %s", ++numbering[0], title->value());
            numbering[1] = 0;
            numbering[2] = 0;
        }
    }
    else if (level == 1)
    {
        style_class = "toc2";
        if (not_numbered)
        {
            sprintf(fulltitle, title->value());
        }
        else
        {
            sprintf(fulltitle, "%i.%i %s", numbering[0], ++numbering[1], title->value());
            numbering[2] = 0;
        }
    }
    else if (level == 2)
    {
        style_class = "toc3";
        if (not_numbered)
        {
            sprintf(fulltitle, title->value());
        }
        else
        {
            sprintf(fulltitle, "%i.%i.%i %s", numbering[0], numbering[1], ++numbering[2], title->value());
        }
    }
    else
        throw std::exception("Invalid TOC level");
    xml_node<char> *tocentry = doc.allocate_node(node_element, "a", fulltitle);
    char *link = doc.allocate_string(0, id->value_size() + 1);
    memcpy(link + 1, id->value(), id->value_size());
    link[0] = '#';
    tocentry->append_attribute(doc.allocate_attribute("href", link, 0, id->value_size() + 1));
    tocentry->append_attribute(doc.allocate_attribute("class", style_class));
    toc.append_node(tocentry);
    toc.append_node(doc.allocate_node(node_element, "br"));
    xml_node<char> *title_data = title->first_node();
    if (title_data)
        title->remove_node(title_data);
    title->value(fulltitle);
}
Ejemplo n.º 2
0
/**
 * @brief WrapperXml::writeXml, metodo para escribir un xml
 * @param pRuta, directorio en el que se guardara el documento
 * @param pRoot, raiz del documento
 * @param pSon, hijo del documento
 */
void WrapperXml::writeCreateSchemeXml(std::string pMsg, xml_document<> &pDocument){
    xml_node<>* decl = pDocument.allocate_node(node_declaration);
    decl->append_attribute(pDocument.allocate_attribute(VERSION, NUMVERSION));
    decl->append_attribute(pDocument.allocate_attribute(ENCODE, TYPEENCODE));
    pDocument.append_node(decl);

    xml_node<>* root = pDocument.allocate_node(node_element, SCHEME);
    pDocument.append_node(root);

    std::istringstream pBuffer(pMsg);
    std::string subString;
    pBuffer >> subString;
    xml_node<>* childSN = pDocument.allocate_node(node_element, SCHEMENAME);
    childSN->value(strdup(subString.c_str()));
    root->append_node(childSN);
    pBuffer >> subString;
    xml_node<>* childR = pDocument.allocate_node(node_element, RAID);
    childR->value(strdup(subString.c_str()));
    root->append_node(childR);

    while(pBuffer){
        pBuffer >> subString;
        if(subString==HASH)
            break;
        else{
            xml_node<>* childD = pDocument.allocate_node(node_element, DATA);
            xml_node<>* childDT = pDocument.allocate_node(node_element, DATATYPE);
            childDT->value(strdup(subString.c_str()));
            childD->append_node(childDT);
            pBuffer >> subString;
            xml_node<>* childDL = pDocument.allocate_node(node_element, DATANAME );
            childDL->value(strdup(subString.c_str()));
            childD->append_node(childDL);
            pBuffer >> subString;
            xml_node<>* childDN= pDocument.allocate_node(node_element, DATANAME);
            childDN->value(strdup(subString.c_str()));
            childD->append_node(childDN);
            root->append_node(childD);
        }
    }

}
Ejemplo n.º 3
0
 inline xml_node<>* allocate_append_node(xml_node<>* top, const char* name)
 {
     xml_node<>* node = xml_doc.allocate_node(node_element, name);
     top->append_node(node);
     return node;
 }