23 #include "StringUtil.h"
24 bool Element::operator == (
Element ele)
26 if(this->tagName == ele.tagName
27 && this->attributes == ele.attributes
28 && this->attributes == ele.attributes)
34 bool Element::operator == (
Element *ele)
36 if(this->tagName == ele->tagName
37 && this->attributes == ele->attributes
38 && this->attributes == ele->attributes)
44 void Element::addElement(
Element element)
46 this->elements.push_back(element);
47 if(&(this->mapOfEle[element.getTagName()])!=NULL)
48 this->mapOfEle[element.getTagName()] = element;
50 void Element::removeElement(
Element element)
52 for(
unsigned int i=0;i<this->elements.size();i++)
57 this->elements.erase(elements.begin()+i);
58 this->mapOfEle.erase(element.getTagName());
63 void Element::addAttribute(
string key,
string value)
65 this->attributes[key] = value;
67 void Element::removeAttribute(
string key)
69 this->attributes.erase(key);
72 bool Element::isNull()
74 if(this->getTagName()==
"&#@^_NULL_&#@^")
80 typedef map<string,string> AttributeList;
81 typedef vector<Element> ElementList;
82 AttributeList Element::getAttributes()
84 return this->attributes;
86 string Element::getAttribute(
string key)
88 return this->attributes[key];
90 ElementList Element::getChildElements()
92 return this->elements;
94 string Element::getTagName()
98 string Element::getNameSpc()
100 return this->nameSpace;
102 string Element::getNewTagNameSpc(
string tag)
104 if(this->nameSpace!=
"")
105 return (this->nameSpace +
":" + tag);
110 string Element::getTagNameSpc()
112 if(this->nameSpace!=
"")
113 return (this->nameSpace +
":" + this->tagName);
115 return this->tagName;
117 void Element::setTagName(
string tagName)
120 StringUtil::split(vemp, tagName, (
":"));
123 this->tagName = vemp.at(1);
124 this->nameSpace = vemp.at(0);
127 this->tagName = tagName;
130 string Element::getText()
const
135 void Element::setText(
string text)
140 bool Element::getCdata()
const
145 void Element::setCdata(
bool cdata)
150 Element Element::getElementByName(
string name)
152 return this->mapOfEle[name];
155 ElementList Element::getElementsByName(
string name)
158 for(
int i=0;i<(int)this->elements.size();i++)
160 if(this->elements.at(i).getTagName()==name)
161 list.push_back(this->elements.at(i));
166 string Element::render()
169 rend.append(generateStartOpenTag(this->getTagName()));
170 rend.append(generateAttributes(this->getAttributes()));
171 rend.append(generateEndOpenTag());
172 rend.append(this->getText());
173 ElementList elements = this->getChildElements();
174 for(
unsigned int i=0;i<elements.size();i++)
176 rend.append(elements.at(i).render());
178 rend.append(generateCloseTag(this->getTagName()));
182 string Element::renderChildren()
185 ElementList elements = this->getChildElements();
186 for(
unsigned int i=0;i<elements.size();i++)
188 rend.append(elements.at(i).render());