39 #define G_VALUE "GXmlElement::value()"
40 #define G_ATTRIBUTE "GXmlElement::attribute(int&)"
41 #define G_PARSE_START "GXmlElement::parse_start(std::string&)"
42 #define G_PARSE_STOP "GXmlElement::parse_stop(std::string&)"
43 #define G_PARSE_ATTRIBUTE "GXmlElement::parse_attribute(size_t*, "\
180 const std::string& value) :
GXmlNode()
299 std::string msg =
"Method requires a XML element instance that "
300 "contains a single child, but this instance "
302 "Please specify a valid XML element.";
309 std::string msg =
"XML element instance does not contain a text "
310 "element. Please specify a valid XML element.";
315 return (text->
text());
331 #if defined(G_RANGE_CHECK)
355 std::string
value =
"";
358 for (
int i = 0; i <
m_attr.size(); ++i) {
360 value =
m_attr[i]->value();
389 for (
int i = 0; i <
m_attr.size(); ++i) {
427 for (
int i = 0; i <
m_attr.size(); ++i) {
459 for (
int i = 0; i < num; ++i) {
484 for (
int k = 0; k < indent; ++k) {
492 for (
int k = 0; k <
m_attr.size(); ++k) {
524 for (
int i = 0; i <
m_nodes.size(); ++i) {
532 for (
int k = 0; k < indent; ++k) {
554 const int& indent)
const
566 result.append(
"GXmlElement::"+
m_name);
567 for (
int k = 0; k <
m_attr.size(); ++k) {
572 for (
int i = 0; i <
m_nodes.size(); ++i) {
617 for (
int i = 0; i < node.
m_attr.size(); ++i) {
636 for (
int i = 0; i <
m_attr.size(); ++i) {
661 std::size_t pos_start = 0;
664 int n = segment.length();
668 std::string msg =
"Empty XML segment encountered. Please verify the "
675 if (segment[0] ==
'<') {
676 if (n < 2 || (segment.compare(0,1,
"<") != 0) ||
677 (segment.compare(n-1,1,
">") != 0)) {
678 std::string msg =
"Invalid tag brackets encountered in XML "
679 "segment \""+segment+
"\". Please verify the "
687 std::size_t pos = segment.find_first_of(
"\x20\x09\x0d\x0a>", 1);
688 if (pos == pos_start) {
689 std::string msg =
"Whitespace before element name encountered in XML "
690 "segment \""+segment+
"\". Please verify the "
694 if (pos == std::string::npos) {
695 if (pos_start == 1) {
696 std::string msg =
"No element name found in XML segment \""+
697 segment+
"\". Please verify the XML format.";
701 m_name = segment.substr(pos_start, pos-pos_start);
704 while (pos != std::string::npos) {
726 int n = segment.length();
729 if (n < 3 || (segment.compare(0,2,
"</") != 0) ||
730 (segment.compare(n-1,1,
">") != 0)) {
731 std::string msg =
"Incorrect or missing tag brackets encountered in "
732 "XML segment \""+segment+
"\". Please verify the "
738 size_t pos = segment.find_first_of(
"\x20\x09\x0d\x0a>", 2);
740 std::string msg =
"Whitespace encountered after \"</\" in XML "
741 "segment \""+segment+
"\". Please verify the XML "
745 if (pos == std::string::npos) {
746 std::string msg =
"No element name found in XML segment \""+
747 segment+
"\". Please verify the XML format.";
750 std::string
name = segment.substr(2, pos-2);
752 std::string msg =
"Element name \""+name+
"\" found in stop tag in XML "
753 "segment \""+segment+
"\" while start tag has name "
754 "\""+
m_name+
"\". Please verify the XML format.";
759 size_t pos2 = segment.find_first_of(
"\x20\x09\x0d\x0a>", pos);
761 std::string msg =
"Invalid characters encountered after element name "
762 "in XML segment \""+segment+
"\". Please verify the "
791 std::string error = segment.substr(*pos, segment.length()-*pos);
794 std::size_t pos_name_start = segment.find_first_not_of(
"\x20\x09\x0d\x0a/>?", *pos);
795 if (pos_name_start == std::string::npos) {
796 *pos = std::string::npos;
801 std::size_t pos_name_end = segment.find_first_of(
"\x20\x09\x0d\x0a=", pos_name_start);
802 if (pos_name_end == std::string::npos) {
803 std::string msg =
"Invalid or missing attribute name encountered "
804 "in XML segment \""+error+
"\". Please verify "
810 std::size_t pos_equal = segment.find_first_of(
"=", pos_name_end);
811 if (pos_equal == std::string::npos) {
812 std::string msg =
"Missing \"=\" sign for attribute encountered "
813 "in XML segment \""+error+
"\". Please verify "
819 std::size_t pos_value_start = segment.find_first_of(
"\x22\x27", pos_equal);
820 if (pos_value_start == std::string::npos) {
821 std::string msg =
"Invalid or missing attribute value start "
822 "hyphen encountered in XML segment \""+
823 error+
"\". Please verify the XML format.";
828 std::string hyphen = segment.substr(pos_value_start, 1);
830 if (pos_value_start >= segment.length()) {
831 std::string msg =
"Invalid or missing attribute value encountered "
832 "in XML segment \""+error+
"\". Please verify "
838 std::size_t pos_value_end = segment.find_first_of(hyphen, pos_value_start);
839 if (pos_value_end == std::string::npos) {
840 std::string msg =
"Invalid or missing attribute value end hyphen "
841 "encountered in XML segment \""+error+
842 "\". Please verify the XML format.";
847 std::size_t n_name = pos_name_end - pos_name_start;
849 std::string msg =
"Invalid or missing attribute name encountered "
850 "in XML segment \""+error+
"\". Please verify "
854 std::string
name = segment.substr(pos_name_start, n_name);
859 std::size_t n_value = pos_value_end - pos_value_start;
860 std::string
value = segment.substr(pos_value_start-1, n_value+2);
870 if (pos_value_end >= segment.length()) {
871 pos_value_end = std::string::npos;
873 *pos = pos_value_end;
Abstract XML node base class.
GXmlNode & operator=(const GXmlNode &node)
Assignment operator.
virtual std::string print(const GChatter &chatter=NORMAL, const int &indent=0) const
Print XML element.
std::vector< GXmlNode * > m_nodes
Pointer to child nodes.
XML element node class interface definition.
std::string value(void) const
Return string value.
std::vector< GXmlAttribute * > m_attr
Attributes.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
const std::string & name(void) const
Return XML element name.
virtual void clear(void)
Clear XML element.
virtual ~GXmlElement(void)
Destructor.
virtual int size(void) const
Return number of child nodes.
void parse_attribute(size_t *pos, const std::string &segment)
Parse element attribute.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
void remove_attribute(const std::string &name)
Remove attribute from element.
bool has_attribute(const std::string &name) const
Check if element has a given attribute.
void init_members(void)
Initialise class members.
const std::string & name(void) const
Return attribute name.
const std::string & text(void) const
Return text.
const int g_indent
Indent for XML file writing.
XML document node class interface definition.
void copy_members(const GXmlElement &node)
Copy class members.
virtual void printf(const char *format,...)=0
XML text node class interface definition.
GXmlElement(void)
Void constructor.
virtual NodeType type(void) const
Return XML node type.
const std::string & value(void) const
Return attribute value.
virtual bool is_empty(void) const
Signals if node has no child nodes.
void free_members(void)
Delete class members.
GXmlElement & operator=(const GXmlElement &node)
Assignment operator.
std::string m_name
Element name.
#define G_PARSE_ATTRIBUTE
Exception handler interface definition.
virtual void write(GUrl &url, const int &indent=0) const
Write element into URL.
void parse_start(const std::string &segment)
Parse element start segment string.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
void parse_stop(const std::string &segment)
Parse element stop segment string.
std::string fill(const std::string &s, const int &n)
Fill string with n strings of same type.
int attributes(void) const
Return number of attributes.
Filename class interface definition.
virtual GXmlElement * clone(void) const
Clone XML element.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.