本文整理汇总了C++中xml_document::allocate_attribute方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_document::allocate_attribute方法的具体用法?C++ xml_document::allocate_attribute怎么用?C++ xml_document::allocate_attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml_document
的用法示例。
在下文中一共展示了xml_document::allocate_attribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_to_toc
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);
}
示例2: AppendAttribute
void XmlParse::AppendAttribute(const std::string &NewAttributeName, const std::string &NewAttributeValue,
xml_document<> &doc, xml_node<> *ParentNode)
{
xml_attribute<> *attr = doc.allocate_attribute(doc.allocate_string(NewAttributeName.c_str()),
doc.allocate_string(NewAttributeValue.c_str()));
if (ParentNode)
{
ParentNode->append_attribute(attr);
}
}
示例3: writeCreateSchemeXml
/**
* @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);
}
}
}
示例4: process_contextless
//.........这里部分代码省略.........
title->append_attribute(id);
}
}
}
else if (string(node->name()) == "sect2")
{
xml_node<char> *title = node->first_node("title");
if (title)
{
title->name("h3");
xml_attribute<char> *id = node->first_attribute("id");
if (id)
{
xml_attribute<char> *not_numbered = node->first_attribute("not-numbered");
add_to_toc(1, title, id, not_numbered != 0);
id->parent()->remove_attribute(id);
title->append_attribute(id);
}
}
}
else if (string(node->name()) == "sect3")
{
xml_node<char> *title = node->first_node("title");
if (title)
{
title->name("h4");
xml_attribute<char> *id = node->first_attribute("id");
if (id)
{
xml_attribute<char> *not_numbered = node->first_attribute("not-numbered");
add_to_toc(2, title, id, not_numbered != 0);
id->parent()->remove_attribute(id);
title->append_attribute(id);
}
}
}
else if (string(node->name()) == "itemizedlist")
{
node->name("ul");
}
else if (string(node->name()) == "listitem")
{
node->name("li");
}
else if (string(node->name()) == "table")
{
node->append_attribute(doc.allocate_attribute("border", "1"));
node->append_attribute(doc.allocate_attribute("cellpadding", "3pt"));
}
else if (string(node->name()) == "row")
{
node->name("tr");
}
else if (string(node->name()) == "entry")
{
if (node->first_attribute("thead") && string(node->first_attribute("thead")->value()) == "yes")
node->name("th");
else
node->name("td");
xml_node<char> *rowspan = node->first_node("rowspan");
if (rowspan)
{
xml_attribute<char> *attr = rowspan->first_attribute("count");
if (attr)
{
xml_attribute<char> *a = doc.allocate_attribute();
a->name("rowspan");
a->value(attr->value());
node->append_attribute(a);
}
}
}
else if (string(node->name()) == "emphasis")
{
node->name("i");
}
else if (string(node->name()) == "bold")
{
node->name("b");
}
else if (string(node->name()) == "space")
{
node->type(node_data);
int n = 1;
if (node->first_attribute("count"))
n = atoi(node->first_attribute("count")->value());
char *data = doc.allocate_string(0, n);
memset(data, ' ', n);
node->value(data, n);
}
// Process recursively
xml_node<char> *child = node->first_node();
while (child)
{
xml_node<char> *next = child->next_sibling();
process_contextless(child);
child = next;
}
}
示例5: allocate_append_attribute
inline void allocate_append_attribute(xml_node<>* node, const char* attr_name, const char* attr_val)
{
xml_attribute<>* attr = xml_doc.allocate_attribute(attr_name, attr_val);
node->append_attribute(attr);
}