45#define G_LOAD "GXml::load(std::string&)"
46#define G_PARSE "GXml::parse(GUrl&)"
47#define G_PROCESS "GXml::process(GXmlNode*, const std::string&)"
109 if (xml.compare(0, 5,
"<?xml") == 0) {
251 return new GXml(*
this);
544 std::string msg =
"Unable to open file \""+filename.
url()+
"\". Please "
545 "specify a valid file name.";
656 result.append(
"=== GXml ===");
677 std::string result =
print(chatter, 0);
744 bool in_markup =
false;
745 bool in_comment =
false;
750 while ((c = url.
get_char()) != EOF) {
753 if (c ==
'\x85' || c == L
'\x2028') {
755 std::string msg =
"Invalid character with ASCII code "+
757 "segment \""+segment+
"\". Please verify "
773 if (in_markup ==
false) {
783 segment.append(1, (
char)c);
790 segment.append(1, (
char)c);
791 std::string msg =
"Unexpected closing bracket \">\" "
792 "encountered in XML segment \""+segment+
793 "\". Please verify the XML format.";
799 segment.append(1, (
char)c);
811 segment.append(1, (
char)c);
816 int n = segment.length();
818 if (segment.compare(n-3,3,
"-->") == 0) {
838 else if (!in_comment && c ==
'<') {
841 segment.append(1, (
char)c);
844 std::string msg =
"Unexpected opening bracket \"<\" "
845 "encountered in XML segment \""+segment+
846 "\". Please verify the XML format.";
852 segment.append(1, (
char)c);
853 if (!in_comment && segment ==
"<!--") {
862 if (segment.size() > 0) {
873 std::string msg =
"Closing tag ";
878 msg +=
" is missing. Please verify the XML format.";
914 int last = (*current)->
size() - 1;
915 (*current) = (*(*current))[last];
924 std::string msg =
"Unexpected element end tag encountered "
925 "in XML segment \""+segment+
"\". Please "
926 "verify the XML format.";
955 (*current)->
append(comment);
963 if (*current != &
m_root) {
964 std::string msg =
"Unexpected declaration markup encountered "
965 "in XML segment \""+segment+
"\". Please "
966 "verify the XML format.";
970 std::string msg =
"Declaration markup encountered in a line "
971 "different from the first line in XML "
972 "segment \""+segment+
"\". Please "
973 "verify the XML format.";
980 while (pos != std::string::npos) {
988 if (version.length() > 0) {
991 if (encoding.length() > 0) {
994 if (standalone.length() > 0) {
1009 pi.parent(*current);
1010 (*current)->append(pi);
1016 std::string msg =
"Invalid tag in XML segment \""+segment+
"\". Please "
1017 "verify the XML format.";
1038 if (segment.size() > 0) {
1041 size_t pos = segment.find_first_not_of(
"\x20\x09\x0d\x0a\x85");
1042 if (pos != std::string::npos) {
1045 (*current)->append(
GXmlText(segment));
1069 int n = segment.length();
1072 if (n >= 7 && (segment.compare(0,4,
"<!--") == 0) &&
1073 (segment.compare(n-3,3,
"-->") == 0)) {
1078 else if (n >= 7 && (segment.compare(0,6,
"<?xml ") == 0) &&
1079 (segment.compare(n-2,2,
"?>") == 0)) {
1084 else if (n >= 4 && (segment.compare(0,2,
"<?") == 0) &&
1085 (segment.compare(n-2,2,
"?>") == 0)) {
1090 else if (n >= 3 && (segment.compare(0,1,
"<") == 0) &&
1091 (segment.compare(n-2,2,
"/>") == 0)) {
1096 else if (n >= 3 && (segment.compare(0,2,
"</") == 0) &&
1097 (segment.compare(n-1,1,
">") == 0)) {
1102 else if (n >= 2 && (segment.compare(0,1,
"<") == 0) &&
1103 (segment.compare(n-1,1,
">") == 0)) {
Exception handler interface definition.
Filename class interface definition.
File URL class interface definition.
String URL class interface definition.
XML document node class interface definition.
XML element node class interface definition.
Abstract XML node base class interface definition.
XML PI node class interface definition.
XML text node class interface definition.
XML class interface definition.
std::string url(void) const
Return Uniform Resource Locator (URL)
bool exists(void) const
Checks whether file exists.
virtual void close(void)
Close file.
virtual void close(void)
Close file.
virtual int get_char(void) const =0
std::string encoding(void) const
Return encoding.
virtual void clear(void)
Clear XML document.
virtual std::string print(const GChatter &chatter=NORMAL, const int &indent=0) const
Print XML document.
std::string version(void) const
Return version.
virtual void write(GUrl &url, const int &indent=0) const
Write XML document into URL.
std::string standalone(void) const
Return standalone.
const GFilename & filename(void) const
Return filename.
void parse_stop(const std::string &segment)
Parse element stop segment string.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
void parse_attribute(size_t *pos, const std::string &segment)
Parse element attribute.
const std::string & name(void) const
Return XML element name.
Abstract XML node base class.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual void remove(const int &index)
Remove XML child node.
virtual GXmlNode * insert(const int &index, const GXmlNode &node)
Insert XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual void extend(const GXmlNode &node)
Append all XML child nodes from another XML node.
virtual void reserve(const int &num)
Reserve space for child nodes.
virtual bool is_empty(void) const
Signals if node has no child nodes.
virtual GXmlNode * set(const int &index, const GXmlNode &node)
Set XML child node.
virtual int size(void) const
Return number of child nodes.
GXmlNode * parent(void) const
Return parent XML node.
virtual int elements(void) const
Return number of GXMLElement children of node.
XML Processing Instruction node class.
GXmlDocument m_root
Root document node.
void parse(const GUrl &url)
Parse XML URL.
void extend(const GXmlNode &node)
Append all XML child nodes from another XML node in the XML document root.
void process_text(GXmlNode **current, const std::string &segment)
Process text segment.
void clear(void)
Clear XML object.
void free_members(void)
Delete class members.
void copy_members(const GXml &xml)
Copy class members.
void reserve(const int &num)
Reserve space for child nodes in XML document root.
void save(const GFilename &filename) const
Save XML document into file.
GXmlNode * operator[](const int &index)
Return pointer to child of XML document root element.
GXmlElement * element(const int &index)
Return pointer to child element.
void remove(const int &index)
Remove child node from XML document root.
GXmlNode * append(const GXmlNode &node)
Append child node to XML document root.
GXmlNode * set(const int &index, const GXmlNode &node)
Set child node in XML document root.
void process_markup(GXmlNode **current, const std::string &segment)
Process markup segment.
void load(const GFilename &filename)
Load XML document from file.
virtual ~GXml(void)
Destructor.
const GXmlDocument & root(void) const
Return document root.
GXml(void)
Void constructor.
void read(const GUrl &url)
Read XML document from URL.
void write(GUrl &url, const int &indent=0) const
Write XML document into URL.
void init_members(void)
Initialise class members.
int elements(void) const
Return number of child elements in XML document root.
std::string print(const GChatter &chatter=NORMAL) const
Print XML object.
GXml & operator=(const GXml &xml)
Assignment operator.
MarkupType get_markuptype(const std::string &segment) const
Get Markup type of segment.
GXmlNode * insert(const int &index, const GXmlNode &node)
Insert child node into XML document root.
GXml * clone(void) const
Clone XML object.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.