X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..bd6412b6d07c0291a8927375abaa7c0f815e4a96:/include/wx/xml/xml.h diff --git a/include/wx/xml/xml.h b/include/wx/xml/xml.h index 0025a6bbb1..7c36f13b9e 100644 --- a/include/wx/xml/xml.h +++ b/include/wx/xml/xml.h @@ -5,27 +5,13 @@ // Created: 2000/03/05 // RCS-ID: $Id$ // Copyright: (c) 2000 Vaclav Slavik -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -/* ************************************************************************* * - * CAUTION! * - * * - * The API defined in this header *WILL* change in the future and backward * - * compatibility will *not* be preserved. If you use these classes in your * - * application, it probably won't compile with future wxWidgets releases. * - * Use on your own risk. * - * * - * ************************************************************************* */ - #ifndef _WX_XML_H_ #define _WX_XML_H_ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma interface "xml.h" -#endif - #include "wx/defs.h" #if wxUSE_XML @@ -79,8 +65,9 @@ class WXDLLIMPEXP_XML wxXmlProperty public: wxXmlProperty() : m_next(NULL) {} wxXmlProperty(const wxString& name, const wxString& value, - wxXmlProperty *next) + wxXmlProperty *next = NULL) : m_name(name), m_value(value), m_next(next) {} + virtual ~wxXmlProperty() {} wxString GetName() const { return m_name; } wxString GetValue() const { return m_value; } @@ -112,10 +99,10 @@ class WXDLLIMPEXP_XML wxXmlNode public: wxXmlNode() : m_properties(NULL), m_parent(NULL), m_children(NULL), m_next(NULL) {} - wxXmlNode(wxXmlNode *parent,wxXmlNodeType type, - const wxString& name, const wxString& content, - wxXmlProperty *props, wxXmlNode *next); - ~wxXmlNode(); + wxXmlNode(wxXmlNode *parent, wxXmlNodeType type, + const wxString& name, const wxString& content = wxEmptyString, + wxXmlProperty *props = NULL, wxXmlNode *next = NULL); + virtual ~wxXmlNode(); // copy ctor & operator=. Note that this does NOT copy syblings // and parent pointer, i.e. m_parent and m_next will be NULL @@ -127,17 +114,27 @@ public: // user-friendly creation: wxXmlNode(wxXmlNodeType type, const wxString& name, const wxString& content = wxEmptyString); - void AddChild(wxXmlNode *child); - void InsertChild(wxXmlNode *child, wxXmlNode *before_node); - bool RemoveChild(wxXmlNode *child); - void AddProperty(const wxString& name, const wxString& value); - bool DeleteProperty(const wxString& name); + virtual void AddChild(wxXmlNode *child); + virtual bool InsertChild(wxXmlNode *child, wxXmlNode *before_node); + virtual bool RemoveChild(wxXmlNode *child); + virtual void AddProperty(const wxString& name, const wxString& value); + virtual bool DeleteProperty(const wxString& name); // access methods: wxXmlNodeType GetType() const { return m_type; } wxString GetName() const { return m_name; } wxString GetContent() const { return m_content; } + bool IsWhitespaceOnly() const; + int GetDepth(wxXmlNode *grandparent = NULL) const; + + // Gets node content from wxXML_ENTITY_NODE + // The problem is, content is represented as + // wxXML_ENTITY_NODE name="tag", content="" + // |-- wxXML_TEXT_NODE or + // wxXML_CDATA_SECTION_NODE name="" content="content" + wxString GetNodeContent() const; + wxXmlNode *GetParent() const { return m_parent; } wxXmlNode *GetNext() const { return m_next; } wxXmlNode *GetChildren() const { return m_children; } @@ -157,7 +154,7 @@ public: void SetChildren(wxXmlNode *child) { m_children = child; } void SetProperties(wxXmlProperty *prop) { m_properties = prop; } - void AddProperty(wxXmlProperty *prop); + virtual void AddProperty(wxXmlProperty *prop); private: wxXmlNodeType m_type; @@ -171,8 +168,15 @@ private: +// special indentation value for wxXmlDocument::Save +#define wxXML_NO_INDENTATION (-1) - +// flags for wxXmlDocument::Load +enum wxXmlDocumentLoadFlag +{ + wxXMLDOC_NONE = 0, + wxXMLDOC_KEEP_WHITESPACE_NODES = 1 +}; // This class holds XML data/document as parsed by XML parser. @@ -185,21 +189,21 @@ public: const wxString& encoding = wxT("UTF-8")); wxXmlDocument(wxInputStream& stream, const wxString& encoding = wxT("UTF-8")); - ~wxXmlDocument() { delete m_root; } + virtual ~wxXmlDocument() { wxDELETE(m_root); } wxXmlDocument(const wxXmlDocument& doc); wxXmlDocument& operator=(const wxXmlDocument& doc); // Parses .xml file and loads data. Returns TRUE on success, FALSE // otherwise. - bool Load(const wxString& filename, - const wxString& encoding = wxT("UTF-8")); - bool Load(wxInputStream& stream, - const wxString& encoding = wxT("UTF-8")); + virtual bool Load(const wxString& filename, + const wxString& encoding = wxT("UTF-8"), int flags = wxXMLDOC_NONE); + virtual bool Load(wxInputStream& stream, + const wxString& encoding = wxT("UTF-8"), int flags = wxXMLDOC_NONE); // Saves document as .xml file. - bool Save(const wxString& filename) const; - bool Save(wxOutputStream& stream) const; + virtual bool Save(const wxString& filename, int indentstep = 1) const; + virtual bool Save(wxOutputStream& stream, int indentstep = 1) const; bool IsOk() const { return m_root != NULL; } @@ -214,7 +218,8 @@ public: wxString GetFileEncoding() const { return m_fileEncoding; } // Write-access methods: - void SetRoot(wxXmlNode *node) { delete m_root ; m_root = node; } + wxXmlNode *DetachRoot() { wxXmlNode *old=m_root; m_root=NULL; return old; } + void SetRoot(wxXmlNode *node) { wxDELETE(m_root); m_root = node; } void SetVersion(const wxString& version) { m_version = version; } void SetFileEncoding(const wxString& encoding) { m_fileEncoding = encoding; } @@ -235,6 +240,8 @@ private: wxXmlNode *m_root; void DoCopy(const wxXmlDocument& doc); + + DECLARE_CLASS(wxXmlDocument) }; #endif // wxUSE_XML