1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG interface for other wxXml classes
 
   7 // Created:     4-June-2001
 
   9 // Copyright:   (c) 2003 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  16 //---------------------------------------------------------------------------
 
  20 // In order to provide wrappers for wxXmlResourceHandler we need to also
 
  21 // provide the classes for representing and parsing XML.
 
  24 // Represents XML node type.
 
  27     // note: values are synchronized with xmlElementType from libxml
 
  31     wxXML_CDATA_SECTION_NODE,
 
  32     wxXML_ENTITY_REF_NODE,
 
  37     wxXML_DOCUMENT_TYPE_NODE,
 
  38     wxXML_DOCUMENT_FRAG_NODE,
 
  40     wxXML_HTML_DOCUMENT_NODE
 
  45 // Represents node property(ies).
 
  46 // Example: in <img src="hello.gif" id="3"/> "src" is property with value
 
  47 //          "hello.gif" and "id" is property with value "3".
 
  51     wxXmlProperty(const wxString& name = wxPyEmptyString,
 
  52                   const wxString& value = wxPyEmptyString,
 
  53                   wxXmlProperty *next = NULL);
 
  55     wxString GetName() const;
 
  56     wxString GetValue() const;
 
  57     wxXmlProperty *GetNext() const;
 
  59     void SetName(const wxString& name);
 
  60     void SetValue(const wxString& value);
 
  61     void SetNext(wxXmlProperty *next);
 
  67 // Represents node in XML document. Node has name and may have content
 
  68 // and properties. Most common node types are wxXML_TEXT_NODE (name and props
 
  69 // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
 
  70 // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
 
  71 // with content="hi").
 
  73 // If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load
 
  74 // (default is UTF-8).
 
  78     wxXmlNode(wxXmlNode *parent = NULL,
 
  79               wxXmlNodeType type = 0,
 
  80               const wxString& name = wxPyEmptyString,
 
  81               const wxString& content = wxPyEmptyString,
 
  82               wxXmlProperty *props = NULL,
 
  83               wxXmlNode *next = NULL);
 
  87     // user-friendly creation:
 
  88     %RenameCtor(XmlNodeEasy,  wxXmlNode(wxXmlNodeType type, const wxString& name,
 
  89                                   const wxString& content = wxPyEmptyString));
 
  91     void AddChild(wxXmlNode *child);
 
  92     void InsertChild(wxXmlNode *child, wxXmlNode *before_node);
 
  93     bool RemoveChild(wxXmlNode *child);
 
  94     void AddProperty(wxXmlProperty *prop);
 
  95     %Rename(AddPropertyName,  void,  AddProperty(const wxString& name, const wxString& value));
 
  96     bool DeleteProperty(const wxString& name);
 
  99     wxXmlNodeType GetType() const;
 
 100     wxString GetName() const;
 
 101     wxString GetContent() const;
 
 103     wxXmlNode *GetParent() const;
 
 104     wxXmlNode *GetNext() const;
 
 105     wxXmlNode *GetChildren() const;
 
 107     wxXmlProperty *GetProperties() const;
 
 108     wxString GetPropVal(const wxString& propName,
 
 109                         const wxString& defaultVal) const;
 
 110     bool HasProp(const wxString& propName) const;
 
 112     void SetType(wxXmlNodeType type);
 
 113     void SetName(const wxString& name);
 
 114     void SetContent(const wxString& con);
 
 116     void SetParent(wxXmlNode *parent);
 
 117     void SetNext(wxXmlNode *next);
 
 118     void SetChildren(wxXmlNode *child);
 
 120     void SetProperties(wxXmlProperty *prop);
 
 125 // This class holds XML data/document as parsed by XML parser.
 
 126 class wxXmlDocument : public wxObject
 
 129     wxXmlDocument(const wxString& filename,
 
 130                   const wxString& encoding = wxPyUTF8String);
 
 131     %RenameCtor(XmlDocumentFromStream,  wxXmlDocument(wxInputStream& stream,
 
 132                                                 const wxString& encoding = wxPyUTF8String));
 
 133     %RenameCtor(EmptyXmlDocument,  wxXmlDocument());
 
 138     // Parses .xml file and loads data. Returns True on success, False
 
 140     bool Load(const wxString& filename,
 
 141               const wxString& encoding = wxPyUTF8String);
 
 142     %Rename(LoadFromStream, bool,  Load(wxInputStream& stream,
 
 143                                    const wxString& encoding = wxPyUTF8String));
 
 145     // Saves document as .xml file.
 
 146     bool Save(const wxString& filename) const;
 
 147     %Rename(SaveToStream, bool,  Save(wxOutputStream& stream) const);
 
 151     // Returns root node of the document.
 
 152     wxXmlNode *GetRoot() const;
 
 154     // Returns version of document (may be empty).
 
 155     wxString GetVersion() const;
 
 157     // Returns encoding of document (may be empty).
 
 158     // Note: this is the encoding original file was saved in, *not* the
 
 159     // encoding of in-memory representation!
 
 160     wxString GetFileEncoding() const;
 
 162     // Write-access methods:
 
 163     void SetRoot(wxXmlNode *node);
 
 164     void SetVersion(const wxString& version);
 
 165     void SetFileEncoding(const wxString& encoding);
 
 168 //         // Returns encoding of in-memory representation of the document (same
 
 169 //         // as passed to Load or ctor, defaults to UTF-8).  NB: this is
 
 170 //         // meaningless in Unicode build where data are stored as wchar_t*
 
 171 //         wxString GetEncoding() {
 
 172 //         %#if wxUSE_UNICODE
 
 173 //             return wxPyEmptyString;
 
 175 //             return self->GetEncoding();
 
 178 //         void SetEncoding(const wxString& enc) {
 
 179 //         %#if wxUSE_UNICODE
 
 182 //             self->SetEncoding(enc);
 
 188 //---------------------------------------------------------------------------
 
 189 //---------------------------------------------------------------------------