/// \deprecated use rootTag() instead tag *getRootTag() const { return rootTag(); }
/// \deprecated use rootTag(t) instead void setRootTag(tag *newroot) { rootTag(newroot); }
void XMLPathTraversalTest() { typedef std::map<std::basic_string<wchar_t>, std::basic_string<wchar_t> > AttributesType; TagElement<wchar_t> rootTag(L"root"); TagElement<wchar_t> childTag1(L"child1"); TagElement<wchar_t> childTag1_(L"child1"); TagElement<wchar_t> childTag2(L"child2"); StringElement<wchar_t> stringTag(L"string"); CommentElement<wchar_t> commentTag(L"comment"); rootTag.addChild(&childTag1); rootTag.addChild(&childTag2); rootTag.addChild(&childTag1_); childTag1.addChild(&stringTag); childTag1_.addChild(&commentTag); CPPUNIT_ASSERT(rootTag.children.size() == 3); CPPUNIT_ASSERT(dynamic_cast<TagElement<wchar_t>*> (rootTag.getChildElement(L"child1"))->getTagName() == L"child1"); CPPUNIT_ASSERT(dynamic_cast<TagElement<wchar_t>*> (rootTag.getChildElement(L"child2"))->getTagName() == L"child2"); std::vector<Element<wchar_t>*> result; XMLPath<wchar_t> path_root(L"/root"); result = path_root.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 1); CPPUNIT_ASSERT(result[0] == &rootTag); XMLPath<wchar_t> path_roots(L"/root[]"); result = path_roots.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 1); CPPUNIT_ASSERT(result[0] == &rootTag); XMLPath<wchar_t> path_child1(L"/root/child1"); result = path_child1.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 1); CPPUNIT_ASSERT(result[0] == &childTag1); XMLPath<wchar_t> path_child1s(L"/root/child1[]"); result = path_child1s.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 2); CPPUNIT_ASSERT(result[0] == &childTag1); CPPUNIT_ASSERT(result[1] == &childTag1_); XMLPath<wchar_t> path_text(L"/root/child1[]/#text"); result = path_text.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 1); CPPUNIT_ASSERT(result[0] == &stringTag); XMLPath<wchar_t> path_comment(L"/root/child1[]/#comment"); result = path_comment.evaluate(&rootTag); CPPUNIT_ASSERT(result.size() == 1); CPPUNIT_ASSERT(result[0] == &commentTag); rootTag.removeChild(&childTag1); rootTag.removeChild(&childTag2); rootTag.removeChild(&childTag1_); childTag1.removeChild(&stringTag); childTag1_.removeChild(&commentTag); }