|
Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
|
00001 /* RapicornXmlNode 00002 * Copyright (C) 2007 Tim Janik 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * A copy of the GNU Lesser General Public License should ship along 00015 * with this library; if not, see http://www.gnu.org/copyleft/. 00016 */ 00017 #ifndef __RAPICORN_XML_HH__ 00018 #define __RAPICORN_XML_HH__ 00019 00020 #include <rcore/markup.hh> 00021 00022 namespace Rapicorn { 00023 00024 class XmlNode : public virtual BaseObject { 00025 String m_name; // element name 00026 XmlNode *m_parent; 00027 StringVector m_attribute_names; 00028 StringVector m_attribute_values; 00029 uint m_line, m_char; 00030 protected: 00031 explicit XmlNode (const String &, uint, uint); 00032 virtual uint64 flags (uint64*) = 0; 00033 virtual ~XmlNode (); 00034 static void set_parent (XmlNode *c, XmlNode *p); 00035 public: 00036 typedef const vector<XmlNode*> ConstNodes; 00037 typedef ConstNodes::const_iterator ConstChildIter; 00038 String name () const { return m_name; } 00039 XmlNode* parent () const { return m_parent; } 00040 const StringVector list_attributes () const { return m_attribute_names; } 00041 bool set_attribute (const String &name, 00042 const String &value, 00043 bool replace = true); 00044 String get_attribute (const String &name, 00045 bool case_insensitive = false) const; 00046 bool has_attribute (const String &name, 00047 bool case_insensitive = false) const; 00048 bool del_attribute (const String &name); 00049 uint parsed_line () const { return m_line; } 00050 uint parsed_char () const { return m_char; } 00051 /* text node */ 00052 virtual String text () const = 0; 00053 bool istext () const { return m_name.size() == 0; } 00054 /* parent node */ 00055 virtual ConstNodes& children () const = 0; 00056 ConstChildIter children_begin () const { return children().begin(); } 00057 ConstChildIter children_end () const { return children().end(); } 00058 const XmlNode* first_child (const String &element_name) const; 00059 virtual bool add_child (XmlNode &child) = 0; 00060 virtual bool del_child (XmlNode &child) = 0; 00061 void steal_children (XmlNode &parent); 00062 /* hints */ 00063 void break_after (bool newline_after_tag); 00064 bool break_after () const; 00065 void break_within (bool newlines_around_chidlren); 00066 bool break_within () const; 00067 /* nodes */ 00068 static XmlNode* create_text (const String &utf8text, 00069 uint line = 0, 00070 uint _char = 0); 00071 static XmlNode* create_parent (const String &element_name, 00072 uint line = 0, 00073 uint _char = 0); 00074 /* IO */ 00075 static XmlNode* parse_xml (const String &input_name, 00076 const char *utf8data, 00077 ssize_t utf8data_len, 00078 MarkupParser::Error *error, 00079 const String &roottag = ""); 00080 String xml_string (uint64 indent = 0); 00081 }; 00082 00083 } // Rapicorn 00084 00085 #endif /* __RAPICORN_XML_HH__ */
1.7.4