Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
partons
core
elementary-utils
Commits
629ac4c1
Commit
629ac4c1
authored
Nov 17, 2016
by
Bryan Berthou
Browse files
refs#16
In ElementaryUtils (trunk) : - Improve XMLParser : add emptyStartElement(...) method.
parent
50c292e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/ElementaryUtils/parser/XMLParser.h
View file @
629ac4c1
...
...
@@ -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:
...
...
src/ElementaryUtils/logger/CustomException.cpp
View file @
629ac4c1
...
...
@@ -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 */
src/ElementaryUtils/parser/XMLParser.cpp
View file @
629ac4c1
...
...
@@ -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
)
{
//
e
xtract end element name
//
E
xtract 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
);
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment