TEST(TestMeiElement, TestGetSet) { MeiElement *p = new MeiElement("p"); p->setValue("this is a sentence"); ASSERT_EQ("this is a sentence", p->getValue()); p->setTail("atail"); // We know an id is 'm-<uuid>', so we can check the length ASSERT_EQ(38, p->getId().length()); ASSERT_EQ("atail", p->getTail()); }
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; }