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 ";
875 if (element != NULL) {
876 msg +=
"for GXmlElement \""+element->
name()+
"\"";
878 msg +=
" is missing. Please verify the XML format.";
913 (*current)->
append(element);
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.";
935 (*current) = element->
parent();
944 (*current)->
append(element);
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) {
985 std::string version = element->
attribute(
"version");
986 std::string encoding = element->
attribute(
"encoding");
987 std::string standalone = element->
attribute(
"standalone");
988 if (version.length() > 0) {
991 if (encoding.length() > 0) {
994 if (standalone.length() > 0) {
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)) {
Abstract XML node base class.
GXmlNode * parent(void) const
Return parent XML node.
void read(const GUrl &url)
Read XML document from URL.
void free_members(void)
Delete class members.
XML Processing Instruction node class.
XML element node class interface definition.
void save(const GFilename &filename) const
Save XML document into file.
virtual GXmlNode * set(const int &index, const GXmlNode &node)
Set XML child node.
XML class interface definition.
std::string standalone(void) const
Return standalone.
GXmlDocument m_root
Root document node.
std::string print(const GChatter &chatter=NORMAL) const
Print XML object.
virtual int elements(void) const
Return number of GXMLElement children of node.
void clear(void)
Clear XML object.
virtual void write(GUrl &url, const int &indent=0) const
Write XML document into URL.
XML PI node class interface definition.
void reserve(const int &num)
Reserve space for child nodes in XML document root.
void load(const GFilename &filename)
Load XML document from file.
void write(GUrl &url, const int &indent=0) const
Write XML document into URL.
File URL class interface definition.
const std::string & name(void) const
Return XML element name.
GXmlNode * insert(const int &index, const GXmlNode &node)
Insert child node into XML document root.
virtual void extend(const GXmlNode &node)
Append all XML child nodes from another XML node.
virtual GXmlNode * insert(const int &index, const GXmlNode &node)
Insert XML child node.
void extend(const GXmlNode &node)
Append all XML child nodes from another XML node in the XML document root.
virtual int size(void) const
Return number of child nodes.
void parse_attribute(size_t *pos, const std::string &segment)
Parse element attribute.
GXmlElement * element(const int &index)
Return pointer to child element.
int elements(void) const
Return number of child elements in XML document root.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
void init_members(void)
Initialise class members.
virtual void reserve(const int &num)
Reserve space for child nodes.
bool exists(void) const
Checks whether file exists.
std::string version(void) const
Return version.
virtual void close(void)
Close file.
GXmlNode * set(const int &index, const GXmlNode &node)
Set child node in XML document root.
virtual void close(void)
Close file.
GXmlNode * operator[](const int &index)
Return pointer to child of XML document root element.
void remove(const int &index)
Remove child node from XML document root.
XML document node class interface definition.
void copy_members(const GXml &xml)
Copy class members.
const GXmlDocument & root(void) const
Return document root.
void process_markup(GXmlNode **current, const std::string &segment)
Process markup segment.
XML text node class interface definition.
void parse(const GUrl &url)
Parse XML URL.
virtual int get_char(void) const =0
std::string url(void) const
Return Uniform Resource Locator (URL)
GXml * clone(void) const
Clone XML object.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
GXml(void)
Void constructor.
std::string encoding(void) const
Return encoding.
virtual bool is_empty(void) const
Signals if node has no child nodes.
GXml & operator=(const GXml &xml)
Assignment operator.
Exception handler interface definition.
MarkupType get_markuptype(const std::string &segment) const
Get Markup type of segment.
const GFilename & filename(void) const
Return filename.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
void parse_stop(const std::string &segment)
Parse element stop segment string.
virtual ~GXml(void)
Destructor.
virtual std::string print(const GChatter &chatter=NORMAL, const int &indent=0) const
Print XML document.
Abstract XML node base class interface definition.
virtual void clear(void)
Clear XML document.
String URL class interface definition.
void process_text(GXmlNode **current, const std::string &segment)
Process text segment.
Filename class interface definition.
GXmlNode * append(const GXmlNode &node)
Append child node to XML document root.
virtual void remove(const int &index)
Remove XML child node.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.