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);
 
  63     %property(Name, GetName, SetName, doc="See `GetName` and `SetName`");
 
  64     %property(Next, GetNext, SetNext, doc="See `GetNext` and `SetNext`");
 
  65     %property(Value, GetValue, SetValue, doc="See `GetValue` and `SetValue`");
 
  71 // Represents node in XML document. Node has name and may have content
 
  72 // and properties. Most common node types are wxXML_TEXT_NODE (name and props
 
  73 // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
 
  74 // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
 
  75 // with content="hi").
 
  77 // If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load
 
  78 // (default is UTF-8).
 
  82     wxXmlNode(wxXmlNode *parent = NULL,
 
  83               wxXmlNodeType type = 0,
 
  84               const wxString& name = wxPyEmptyString,
 
  85               const wxString& content = wxPyEmptyString,
 
  86               wxXmlProperty *props = NULL,
 
  87               wxXmlNode *next = NULL);
 
  91     // user-friendly creation:
 
  92     %RenameCtor(XmlNodeEasy,  wxXmlNode(wxXmlNodeType type, const wxString& name,
 
  93                                   const wxString& content = wxPyEmptyString));
 
  95     void AddChild(wxXmlNode *child);
 
  96     bool InsertChild(wxXmlNode *child, wxXmlNode *before_node);
 
  97     bool RemoveChild(wxXmlNode *child);
 
  98     void AddProperty(wxXmlProperty *prop);
 
  99     %Rename(AddPropertyName,  void,  AddProperty(const wxString& name, const wxString& value));
 
 100     bool DeleteProperty(const wxString& name);
 
 103     wxXmlNodeType GetType() const;
 
 104     wxString GetName() const;
 
 105     wxString GetContent() const;
 
 107     bool IsWhitespaceOnly() const;
 
 108     int GetDepth(wxXmlNode *grandparent = NULL) const;
 
 110     // Gets node content from wxXML_ENTITY_NODE
 
 111     // The problem is, <tag>content<tag> is represented as
 
 112     // wxXML_ENTITY_NODE name="tag", content=""
 
 113     //    |-- wxXML_TEXT_NODE or
 
 114     //        wxXML_CDATA_SECTION_NODE name="" content="content"
 
 115     wxString GetNodeContent() const;
 
 117     wxXmlNode *GetParent() const;
 
 118     wxXmlNode *GetNext() const;
 
 119     wxXmlNode *GetChildren() const;
 
 121     wxXmlProperty *GetProperties() const;
 
 122     wxString GetPropVal(const wxString& propName,
 
 123                         const wxString& defaultVal) const;
 
 124     bool HasProp(const wxString& propName) const;
 
 126     void SetType(wxXmlNodeType type);
 
 127     void SetName(const wxString& name);
 
 128     void SetContent(const wxString& con);
 
 130     void SetParent(wxXmlNode *parent);
 
 131     void SetNext(wxXmlNode *next);
 
 132     void SetChildren(wxXmlNode *child);
 
 134     void SetProperties(wxXmlProperty *prop);
 
 136     %property(Children, GetChildren, SetChildren, doc="See `GetChildren` and `SetChildren`");
 
 137     %property(Content, GetContent, SetContent, doc="See `GetContent` and `SetContent`");
 
 138     %property(Name, GetName, SetName, doc="See `GetName` and `SetName`");
 
 139     %property(Next, GetNext, SetNext, doc="See `GetNext` and `SetNext`");
 
 140     %property(Parent, GetParent, SetParent, doc="See `GetParent` and `SetParent`");
 
 141     %property(Properties, GetProperties, SetProperties, doc="See `GetProperties` and `SetProperties`");
 
 142     %property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
 
 147 // special indentation value for wxXmlDocument::Save
 
 152 // flags for wxXmlDocument::Load
 
 153 enum wxXmlDocumentLoadFlag
 
 156     wxXMLDOC_KEEP_WHITESPACE_NODES = 1
 
 161 // This class holds XML data/document as parsed by XML parser.
 
 162 class wxXmlDocument : public wxObject
 
 165     wxXmlDocument(const wxString& filename,
 
 166                   const wxString& encoding = wxPyUTF8String);
 
 167     %RenameCtor(XmlDocumentFromStream,  wxXmlDocument(wxInputStream& stream,
 
 168                                                 const wxString& encoding = wxPyUTF8String));
 
 169     %RenameCtor(EmptyXmlDocument,  wxXmlDocument());
 
 174     // Parses .xml file and loads data. Returns True on success, False
 
 176     bool Load(const wxString& filename,
 
 177               const wxString& encoding = wxPyUTF8String,
 
 178               int flags = wxXMLDOC_NONE);
 
 179     %Rename(LoadFromStream, bool,  Load(wxInputStream& stream,
 
 180                                         const wxString& encoding = wxPyUTF8String,
 
 181                                         int flags = wxXMLDOC_NONE));
 
 183     // Saves document as .xml file.
 
 184     bool Save(const wxString& filename, int indentstep=1) const;
 
 185     %Rename(SaveToStream, bool,  Save(wxOutputStream& stream, int indentstep=1) const);
 
 189     // Returns root node of the document.
 
 190     wxXmlNode *GetRoot() const;
 
 192     // Returns version of document (may be empty).
 
 193     wxString GetVersion() const;
 
 195     // Returns encoding of document (may be empty).
 
 196     // Note: this is the encoding original file was saved in, *not* the
 
 197     // encoding of in-memory representation!
 
 198     wxString GetFileEncoding() const;
 
 200     // Write-access methods:
 
 201     wxXmlNode *DetachRoot();
 
 202     void SetRoot(wxXmlNode *node);
 
 203     void SetVersion(const wxString& version);
 
 204     void SetFileEncoding(const wxString& encoding);
 
 207 //         // Returns encoding of in-memory representation of the document (same
 
 208 //         // as passed to Load or ctor, defaults to UTF-8).  NB: this is
 
 209 //         // meaningless in Unicode build where data are stored as wchar_t*
 
 210 //         wxString GetEncoding() {
 
 211 //         %#if wxUSE_UNICODE
 
 212 //             return wxPyEmptyString;
 
 214 //             return self->GetEncoding();
 
 217 //         void SetEncoding(const wxString& enc) {
 
 218 //         %#if wxUSE_UNICODE
 
 221 //             self->SetEncoding(enc);
 
 226     %property(FileEncoding, GetFileEncoding, SetFileEncoding, doc="See `GetFileEncoding` and `SetFileEncoding`");
 
 227     %property(Root, GetRoot, SetRoot, doc="See `GetRoot` and `SetRoot`");
 
 228     %property(Version, GetVersion, SetVersion, doc="See `GetVersion` and `SetVersion`");
 
 231 //---------------------------------------------------------------------------
 
 232 //---------------------------------------------------------------------------