Commit 629ac4c1 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk) :
- Improve XMLParser : add emptyStartElement(...) method.
parent 50c292e4
......@@ -41,6 +41,9 @@ public:
virtual void startElement(const std::string &elementName,
XMLAttributs attributes, const std::string &elementData) = 0;
virtual void emptyStartElement(const std::string &elementName,
XMLAttributs attributes) = 0;
virtual void endElement(const std::string &elementName) = 0;
private:
......
......@@ -20,16 +20,16 @@ const char* CustomException::what() const throw () {
return formatter.str().c_str();
}
} /* namespace ElemUtils */
const std::string& ElemUtils::CustomException::getClassName() const {
const std::string& CustomException::getClassName() const {
return m_className;
}
const std::string& ElemUtils::CustomException::getErrorMsg() const {
const std::string& CustomException::getErrorMsg() const {
return m_errorMsg;
}
const std::string& ElemUtils::CustomException::getFuncName() const {
const std::string& CustomException::getFuncName() const {
return m_funcName;
}
} /* namespace ElemUtils */
......@@ -106,41 +106,56 @@ void XMLParser::parseElement(const std::string& file,
LoggerManager::getInstance()->debug("XMLParser", __func__,
ElemUtils::Formatter()
<< "Test character next to start tag character : "
<< file.at(xmlStartTagIndex + 1));
<< file.substr(xmlStartTagIndex,
xmlEndTagIndex - xmlStartTagIndex));
// End element reach
if (file.at(xmlStartTagIndex + 1)
== XMLParser::XML_END_TAG_CHARACTER_IDENTIFIER) {
// extract end element name
// Extract end element name and set empty attributes
endElement(
file.substr(xmlStartTagIndex + 2,
(xmlEndTagIndex - 1) - (xmlStartTagIndex + 2)));
} else {
// else it's a start element; by default with empty data;
}
// else it's a start element
else {
std::string nodeValue = StringUtils::EMPTY;
if (file.at(xmlEndTagIndex - 1)
!= XMLParser::XML_END_TAG_CHARACTER_IDENTIFIER) {
// it's a element node with data
//TODO retrieve data like <node> some data </node>
// nodeValue = some data;
}
// retrieve element name
size_t elementNameEndIndex = file.find_first_not_of(
XMLParser::XML_TAG_NAME_ALLOWED_CHARACTERS,
xmlStartTagIndex + 1);
// retrieve its attributes
XMLAttributs attributes;
parseAttributesFromXMLElement(file, attributes, elementNameEndIndex,
xmlEndTagIndex);
// it's a EMPTY start element with maybe some attributes
if (file.at(xmlEndTagIndex - 2)
== XMLParser::XML_END_TAG_CHARACTER_IDENTIFIER) {
// retrieve its attributes
XMLAttributs attributes;
parseAttributesFromXMLElement(file, attributes, elementNameEndIndex,
xmlEndTagIndex);
startElement(
file.substr(xmlStartTagIndex + 1,
elementNameEndIndex - (xmlStartTagIndex + 1)),
attributes, nodeValue);
emptyStartElement(
file.substr(xmlStartTagIndex + 1,
elementNameEndIndex - (xmlStartTagIndex + 1)),
attributes);
}
// Else it's a start element with some data or element too
else {
//TODO retrieve data like <node> some data </node>
// retrieve its attributes
XMLAttributs attributes;
parseAttributesFromXMLElement(file, attributes, elementNameEndIndex,
xmlEndTagIndex);
startElement(
file.substr(xmlStartTagIndex + 1,
elementNameEndIndex - (xmlStartTagIndex + 1)),
attributes, nodeValue);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment