本文整理汇总了C++中MeiElement::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ MeiElement::setAttributes方法的具体用法?C++ MeiElement::setAttributes怎么用?C++ MeiElement::setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeiElement
的用法示例。
在下文中一共展示了MeiElement::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MeiElement
// Adding an attribute to an element sets the attr's element.
TEST(TestMeiElement, TestAttributeLink) {
MeiElement *p = new MeiElement("note");
MeiAttribute *a = new MeiAttribute("pname", "c");
p->addAttribute(a);
ASSERT_EQ(p, a->getElement());
// And when adding many attrs
MeiAttribute *b = new MeiAttribute("pname", "d");
MeiAttribute *c = new MeiAttribute("stem.dir", "down");
vector<MeiAttribute*> atts;
atts.push_back(b);
atts.push_back(c);
p->setAttributes(atts);
ASSERT_EQ(2, p->getAttributes().size());
ASSERT_EQ(p, b->getElement());
ASSERT_EQ(p, c->getElement());
}
示例2: xmlNodeToMeiElement
MeiElement* XmlImportImpl::xmlNodeToMeiElement(xmlNode *el) {
string id = "";
vector<MeiAttribute*> attributes;
// XML attributes and children. Text nodes will never have these.
if (el->properties) {
xmlAttr *curattr = NULL;
for (curattr = el->properties; curattr; curattr = curattr->next) {
if (curattr->atype == XML_ATTRIBUTE_ID) {
/* we store the ID on the element, not as an attribute. This will be serialized out
* on export
*/
id = (const char*)curattr->children->content;
} else {
string attrname = (const char*)curattr->name;
// values are rendered as children of the attribute *facepalm*
string attrvalue = (const char*)curattr->children->content;
MeiNamespace* meins = NULL;
if (curattr->ns) {
if (!this->meiDocument->hasNamespace(string((const char*)curattr->ns->href))) {
string prefix = (const char*)curattr->ns->prefix;
string href = (const char*)curattr->ns->href;
meins = new MeiNamespace(prefix, href);
} else {
meins = this->meiDocument->getNamespace(string((const char*)curattr->ns->href));
}
}
MeiAttribute *a = new MeiAttribute(meins, attrname, attrvalue);
attributes.push_back(a);
}
}
}
MeiElement *obj = MeiFactory::createInstance((const char*)el->name, id);
obj->setAttributes(attributes);
MeiElement *lastElement = NULL;
xmlNodePtr child = el->children;
while (child != NULL) {
if (child->type == XML_ELEMENT_NODE) {
MeiElement* ch = xmlNodeToMeiElement(child);
obj->addChild(ch);
lastElement = ch;
} else if (child->type == XML_TEXT_NODE) {
if (lastElement) {
const char *content = (const char*)child->content;
if (content) {
lastElement->setTail(content);
}
} else {
const char *content = (const char*)child->content;
if (content) {
obj->setValue(content);
}
}
} else if (child->type == XML_COMMENT_NODE) {
MeiElement *comment = new MeiCommentNode();
comment->setValue(string((const char*)child->content));
obj->addChild(comment);
}
child = child->next;
}
return obj;
}