00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
00012 #ifndef _WX_XML2_H_
00013 #define _WX_XML2_H_
00014
00015
00016 #include "wx/string.h"
00017 #include "wx/object.h"
00018 #include "wx/wfstream.h"
00019
00020
00021 #include "wx/xml2def.h"
00022
00023
00024
00025 #if defined(__GNUG__) && defined(__WXMSW__)
00026 #define LIBXML_STATIC
00027 #endif
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <libxml/xmlmemory.h>
00039 #include <libxml/parser.h>
00040
00041
00042
00043
00044
00045
00046
00058 #define wxCHECK_NULL_POINTERS(x, y) \
00059 if (x == NULL && y == NULL) \
00060 return TRUE; \
00061 if ((x == NULL && y != NULL) || \
00062 (x != NULL && y == NULL)) \
00063 return FALSE;
00064
00068 #if wxUSE_UNICODE
00069
00070
00071
00072 #define WX2XML(str) ((xmlChar *)(str.mb_str(wxConvUTF8).data()))
00073 #else
00074
00075
00076 #define WX2XML(str) ((xmlChar *)(str.mb_str(wxConvUTF8)))
00077 #endif
00078
00079
00084 #define XML2WX(str) (wxString((const char *)str, wxConvUTF8))
00085
00086
00091 #define wxXML2DOC_USE_NATIVE_NEWLINES 1
00092
00095 #define wxXML2DOC_USE_INDENTATION 2
00096
00097
00098
00099
00100
00101
00102
00103
00104
00107 enum wxXml2NodeType
00108 {
00109
00110
00111
00121 wxXML2_ELEMENT_NODE = 1,
00122
00124 wxXML2_TEXT_NODE = 3,
00125
00130 wxXML2_CDATA_SECTION_NODE = 4,
00131
00137 wxXML2_ENTITY_REF_NODE = 5,
00138
00144 wxXML2_PI_NODE = 7,
00145
00147 wxXML2_COMMENT_NODE = 8,
00148
00152 wxXML2_DOCUMENT_NODE = 9,
00153 wxXML2_HTML_DOCUMENT_NODE = 13,
00154
00155
00159 wxXML2_DTD_NODE = 14,
00160
00164 wxXML2_ELEMENT_DECL = 15,
00165
00169 wxXML2_ATTRIBUTE_DECL = 16,
00170
00174 wxXML2_ENTITY_DECL = 17,
00175
00176
00180 wxXML2_NAMESPACE_DECL = 18
00181
00182
00183
00184
00185 };
00186
00187
00191 typedef struct tagXml2BaseNode {
00192
00193 void *_private;
00194 xmlElementType type;
00195 const xmlChar *name;
00196 struct tagXml2BaseNode *children;
00197 struct tagXml2BaseNode *last;
00198 struct tagXml2BaseNode *parent;
00199 struct tagXml2BaseNode *next;
00200 struct tagXml2BaseNode *prev;
00201 struct _xmlDoc *doc;
00202
00203 } wxXml2BaseNodeObj;
00204
00205
00206 class WXDLLIMPEXP_WXXML2 wxXml2BaseNode;
00207 class WXDLLIMPEXP_WXXML2 wxXml2Node;
00208 class WXDLLIMPEXP_WXXML2 wxXml2Property;
00209 class WXDLLIMPEXP_WXXML2 wxXml2Namespace;
00210 class WXDLLIMPEXP_WXXML2 wxXml2Document;
00211 class WXDLLIMPEXP_WXXML2 wxXml2DTD;
00212
00213
00214 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2Node) wxXml2EmptyNode;
00215 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2Property) wxXml2EmptyProperty;
00216 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2Namespace) wxXml2EmptyNamespace;
00217 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2Document) wxXml2EmptyDoc;
00218 extern WXDLLIMPEXP_DATA_WXXML2(wxXml2BaseNode) wxXml2EmptyBaseNode;
00219
00220
00221
00222
00223
00224
00225
00226
00227
00242 #define wxXML2CHECK_VERSION(major,minor,release) \
00243 (LIBXML_VERSION >= major##0##minor##release)
00244
00245
00246
00247 #if !wxXML2CHECK_VERSION(2, 6, 10)
00248 #error wxXml2 requires at least libxml2 2.6.1; please download it from http://xmlsoft.org
00249 #endif
00250
00255 class WXDLLIMPEXP_WXXML2 wxXml2 : public wxObject
00256 {
00257 static char m_strIndent[32];
00258 static const char *m_strOld;
00259 static int m_nOld;
00260
00261 public:
00262 wxXml2() {}
00263 virtual ~wxXml2() {}
00264
00267 static void Init()
00268 { xmlInitMemory(); xmlInitParser(); }
00269
00273 static void Cleanup()
00274 { xmlCleanupParser(); }
00275
00278 static wxString GetLibxml2Version()
00279 { return wxT(LIBXML_DOTTED_VERSION); }
00280
00283 static void TestLibxml2Version()
00284 { LIBXML_TEST_VERSION; }
00285
00287 static xmlGlobalState *GetGlobalState()
00288 { return xmlGetGlobalState(); }
00289
00292 static void SetIndentMode(bool benable = TRUE, int indentstep = 4);
00293
00296 static void RestoreLastIndentMode();
00297 };
00298
00299
00300
00307 class WXDLLIMPEXP_WXXML2 wxXml2Wrapper : public wxObject
00308 {
00309 DECLARE_ABSTRACT_CLASS(wxXml2Wrapper)
00310
00311 protected:
00312
00316 virtual void Destroy() = 0;
00317
00322 virtual void SetAsEmpty() = 0;
00323
00326
00327
00329 virtual int &GetPrivate() const = 0;
00330
00331 protected:
00332
00482
00483 void ResetRefCount()
00484 { if (IsNonEmpty()) GetPrivate() = 0; }
00485
00486 void IncRefCount()
00487 { if (IsNonEmpty()) GetPrivate()++; }
00488
00489 void DecRefCount()
00490 { if (IsNonEmpty()) GetPrivate()--; }
00491
00492 int GetRefCount() const
00493 { if (IsNonEmpty()) return (int)(GetPrivate()); else return 0; }
00494
00497 void UnwrappingOld()
00498 { DestroyIfUnlinked(); }
00499
00502 void JustWrappedNew()
00503 { IncRefCount(); }
00504
00505 public:
00506
00508 wxXml2Wrapper() {}
00509
00514 virtual ~wxXml2Wrapper() {}
00515
00516
00518 virtual bool IsUnlinked() const = 0;
00519
00521 virtual bool IsNonEmpty() const = 0;
00522
00524 virtual void DestroyIfUnlinked();
00525 };
00526
00527
00528
00533 class WXDLLIMPEXP_WXXML2 wxXml2Property : public wxXml2Wrapper
00534 {
00535 DECLARE_DYNAMIC_CLASS(wxXml2Property)
00536
00537
00538 xmlAttr *m_attr;
00539
00540 protected:
00541
00542 void Destroy() {
00543 if (m_attr) xmlRemoveProp(m_attr);
00544 SetAsEmpty();
00545 }
00546
00547 void SetAsEmpty()
00548 { m_attr = NULL; }
00549
00550 void Copy(const wxXml2Property &prop)
00551 { UnwrappingOld(); m_attr = prop.m_attr; JustWrappedNew(); }
00552
00553 int &GetPrivate() const
00554 { return (int &)(m_attr->_private); }
00555
00556 public:
00557
00559 wxXml2Property() : m_attr(NULL) {}
00560
00562 wxXml2Property(const wxString &name,
00563 const wxString &value,
00564 wxXml2Node &owner = wxXml2EmptyNode) : m_attr(NULL)
00565 { Create(name, value, owner); }
00566
00568 wxXml2Property(xmlAttr *pattr) : m_attr(pattr)
00569 { JustWrappedNew(); }
00570
00572 wxXml2Property(const wxXml2Property &prop) : wxXml2Wrapper(), m_attr(NULL)
00573 { Copy(prop); }
00574
00576 virtual ~wxXml2Property() { DestroyIfUnlinked(); }
00577
00578
00579 public:
00580
00583 bool operator==(const wxXml2Property &p) const;
00584
00586 bool operator!=(const wxXml2Property &p) const { return !(*this == p); }
00587
00589 wxXml2Property &operator=(const wxXml2Property &p)
00590 { Copy(p); return *this; }
00591
00592 public:
00593
00595 void Create(const wxString &name,
00596 const wxString &value,
00597 wxXml2Node &owner = wxXml2EmptyNode);
00598
00600 bool IsUnlinked() const;
00601
00603 bool IsNonEmpty() const
00604 { return m_attr != NULL; }
00605
00606
00607 public:
00608
00609 wxString GetName() const
00610 { if (m_attr) return XML2WX(m_attr->name); return wxEmptyString; }
00611 wxString GetValue() const
00612 { if (m_attr->children) return XML2WX(m_attr->children->content); return wxEmptyString; }
00613
00614 wxXml2Property GetNext() const
00615 { if (m_attr) return wxXml2Property(m_attr->next); return wxXml2EmptyProperty; }
00616 wxXml2Property GetPrevious() const
00617 { if (m_attr) return wxXml2Property(m_attr->prev); return wxXml2EmptyProperty; }
00618
00619 wxXml2Node GetOwner() const;
00620
00622 xmlAttr *GetObj() const
00623 { return m_attr; }
00624
00625
00626 public:
00627
00628 void SetValue(const wxString &value);
00629 void SetName(const wxString &name);
00630
00631 void SetNext(wxXml2Property &next);
00632 void SetPrevious(wxXml2Property &prev);
00633
00635 void SetOwner(wxXml2Node &owner);
00636 };
00637
00638
00639
00655 class WXDLLIMPEXP_WXXML2 wxXml2Namespace : public wxXml2Wrapper
00656 {
00657 DECLARE_DYNAMIC_CLASS(wxXml2Namespace)
00658
00659
00660 xmlNs *m_ns;
00661
00666 xmlNode *m_owner;
00667
00668 protected:
00669
00670 void Destroy() {
00671 if (m_ns) xmlFreeNs(m_ns);
00672 SetAsEmpty();
00673 }
00674
00675 void SetAsEmpty()
00676 { m_ns = NULL; }
00677
00678 void Copy(const wxXml2Namespace &ns) {
00679 UnwrappingOld();
00680 m_ns = ns.m_ns;
00681 m_owner = ns.m_owner;
00682 JustWrappedNew();
00683 }
00684
00685 int &GetPrivate() const
00686 { return (int &)(m_ns->_private); }
00687
00688 public:
00689
00691 wxXml2Namespace() : m_ns(NULL), m_owner(NULL) {}
00692
00696 wxXml2Namespace(const wxString &prefix, const wxString &uri,
00697 wxXml2Node &owner = wxXml2EmptyNode) : m_ns(NULL), m_owner(NULL)
00698 { Create(prefix, uri, owner); }
00699
00701 wxXml2Namespace(xmlNs *ns, wxXml2Node &owner);
00702
00704 wxXml2Namespace(const wxXml2Namespace &ns) : wxXml2Wrapper(), m_ns(NULL), m_owner(NULL)
00705 { Copy(ns); }
00706
00709 virtual ~wxXml2Namespace() { DestroyIfUnlinked(); }
00710
00711
00712 public:
00713
00714 bool operator==(const wxXml2Namespace &ns) const;
00715 bool operator!=(const wxXml2Namespace &p) const { return !(*this == p); }
00716
00717 wxXml2Namespace &operator=(const wxXml2Namespace &n)
00718 { Copy(n); return *this; }
00719
00720 public:
00721
00723 void Create(const wxString &prefix, const wxString &uri, wxXml2Node &owner);
00724
00729 bool IsUnlinked() const
00730 { return (m_owner == NULL) || (m_ns == NULL); }
00731
00733 bool IsNonEmpty() const
00734 { return m_ns != NULL; }
00735
00736
00737 public:
00738
00739 wxString GetPrefix() const
00740 { if (m_ns) return XML2WX(m_ns->prefix); return wxEmptyString; }
00741 wxString GetURI() const
00742 { if (m_ns) return XML2WX(m_ns->href); return wxEmptyString; }
00743
00745 xmlNs *GetObj() const
00746 { return m_ns; }
00747
00748 public:
00749
00750 void SetPrefix(const wxString &p);
00751 void SetURI(const wxString &u);
00752 };
00753
00754
00755
00756
00761 class WXDLLIMPEXP_WXXML2 wxXml2Document : public wxXml2Wrapper
00762 {
00763 DECLARE_DYNAMIC_CLASS(wxXml2Document)
00764
00765
00766 xmlDoc *m_doc;
00767
00768 protected:
00769
00770 void Destroy() {
00771 if (m_doc) xmlFreeDoc(m_doc);
00772 SetAsEmpty();
00773 }
00774
00775 void SetAsEmpty()
00776 { m_doc = NULL; }
00777
00778 void Copy(const wxXml2Document &doc) {
00779 UnwrappingOld();
00780 m_doc = doc.m_doc;
00781 JustWrappedNew();
00782 }
00783
00784 int &GetPrivate() const
00785 { return (int &)(m_doc->_private); }
00786
00787 public:
00788
00791 wxXml2Document()
00792 { m_doc = NULL; }
00793
00795 wxXml2Document(wxXml2Node &root);
00796
00798 wxXml2Document(const wxString &filename)
00799 { m_doc = xmlParseFile((const char *)WX2XML(filename)); JustWrappedNew(); }
00800
00802 wxXml2Document(xmlDoc *doc) : m_doc(doc)
00803 { JustWrappedNew(); }
00804
00806 wxXml2Document(const wxXml2Document &doc) : wxXml2Wrapper(), m_doc(NULL)
00807 { Copy(doc); }
00808
00810 virtual ~wxXml2Document()
00811 { DestroyIfUnlinked(); }
00812
00813
00814 public:
00815
00816 bool operator==(const wxXml2Document &doc) const;
00817 bool operator!=(const wxXml2Document &doc) const { return !(*this == doc); }
00818
00819 wxXml2Document &operator=(const wxXml2Document &doc)
00820 { Copy(doc); return *this; }
00821
00822
00823 public:
00824
00826 bool Create(const wxString &version = wxT("1.0"));
00827
00829 bool Load(wxInputStream &stream, wxString *pErr = NULL);
00830
00834 bool Load(const wxString &filename, wxString *pErr = NULL);
00835
00838 int Save(wxOutputStream &stream, const wxString &encoding = wxT("UTF-8"),
00839 long flags = wxXML2DOC_USE_NATIVE_NEWLINES, int indentstep = 4) const;
00840
00843 bool Save(const wxString &filename, const wxString &encoding = wxT("UTF-8"),
00844 long flags = wxXML2DOC_USE_NATIVE_NEWLINES, int indentstep = 4) const;
00845
00846
00847 public:
00848
00850 bool IsNonEmpty() const
00851 { return m_doc != NULL; }
00852
00854 bool IsOk() const
00855 { return xmlDocGetRootElement(m_doc) != NULL; }
00856
00860 bool IsUnlinked() const
00861 { return TRUE; }
00862
00874 bool IsDTDValid(wxString *err = NULL, int bUseInternal = 0) const;
00875
00876 public:
00877
00879 wxXml2Node GetRoot() const;
00880
00888 wxXml2DTD GetDTD() const;
00889
00891 wxString GetVersion() const
00892 { if (m_doc) return XML2WX(m_doc->version); return wxEmptyString; }
00893
00897 wxString GetFileEncoding() const
00898 { if (m_doc) return XML2WX(m_doc->encoding); return wxEmptyString; }
00899
00901 xmlDoc *GetObj() const
00902 { return m_doc; }
00903
00904
00905 public:
00906
00908 void SetRoot(wxXml2Node &node);
00909
00911 void SetDTD(wxXml2DTD &dtd);
00912
00916 void SetStyleSheet(const wxString &xslfile);
00917
00918 public:
00919
00921 void SetMathMLDTD();
00922
00924 void SetXHTMLStrictDTD();
00925 void SetXHTMLTransitionalDTD();
00926 void SetXHTMLFrameSetDTD();
00927 };
00928
00929
00930
00941 class WXDLLIMPEXP_WXXML2 wxXml2BaseNode : public wxXml2Wrapper
00942 {
00943 DECLARE_DYNAMIC_CLASS(wxXml2BaseNode)
00944
00945
00946 wxXml2BaseNodeObj *m_obj;
00947
00948 protected:
00949
00950 void Destroy() {
00951 if (m_obj) xmlFree(m_obj);
00952 SetAsEmpty();
00953 }
00954
00955 void SetAsEmpty()
00956 { m_obj = NULL; }
00957
00958 void Copy(const wxXml2BaseNode &n) {
00959 UnwrappingOld();
00960 m_obj = n.m_obj;
00961 JustWrappedNew();
00962 }
00963
00964 int &GetPrivate() const
00965 { return (int &)(m_obj->_private); }
00966
00967 public:
00968
00969 wxXml2BaseNode() : m_obj(NULL) {}
00970 wxXml2BaseNode(wxXml2BaseNodeObj *p) : m_obj(p) { JustWrappedNew(); }
00971
00972 virtual ~wxXml2BaseNode() {}
00973
00974
00976 bool IsUnlinked() const;
00977
00979 bool IsNonEmpty() const
00980 { return m_obj != NULL; }
00981
00982
00983 public:
00984
00985 bool operator==(const wxXml2BaseNode &decl) const;
00986 bool operator!=(const wxXml2BaseNode &decl) const { return !(*this == decl); }
00987
00988 wxXml2BaseNode &operator=(const wxXml2BaseNode &decl)
00989 { Copy(decl); return *this; }
00990
00991
00992 public:
00993
00999
01000 wxXml2NodeType GetType() const
01001 { return (wxXml2NodeType)((int)m_obj->type); }
01002 wxXml2BaseNode GetParent() const
01003 { if (m_obj) return wxXml2BaseNode(m_obj->parent); return wxXml2EmptyBaseNode; }
01004 wxXml2BaseNode GetChildren() const
01005 { if (m_obj) return wxXml2BaseNode(m_obj->children); return wxXml2EmptyBaseNode; }
01006 wxXml2BaseNode GetFirstChild() const
01007 { return GetChildren(); }
01008 wxXml2BaseNode GetNext() const
01009 { if (m_obj) return wxXml2BaseNode(m_obj->next); return wxXml2EmptyBaseNode; }
01010 wxXml2BaseNode GetPrevious() const
01011 { if (m_obj) return wxXml2BaseNode(m_obj->prev); return wxXml2EmptyBaseNode; }
01012
01013 wxXml2BaseNodeObj *GetObj() const
01014 { return m_obj; }
01015
01017
01018
01019 public:
01020
01025
01026 void SetType(wxXml2NodeType type)
01027 { m_obj->type = (xmlElementType)((int)type); }
01028
01029 void SetChildren(const wxXml2BaseNode &child);
01030 void SetNext(const wxXml2BaseNode &next);
01031 void SetPrevious(const wxXml2BaseNode &prev);
01032
01034 };
01035
01036
01037
01044 class WXDLLIMPEXP_WXXML2 wxXml2Node : public wxXml2BaseNode
01045 {
01046 DECLARE_DYNAMIC_CLASS(wxXml2Node)
01047
01048 protected:
01049
01054 void Build(const wxXml2NodeType type,
01055 wxXml2Node &parent,
01056 wxXml2Document &document = wxXml2EmptyDoc,
01057 wxXml2Namespace &ns = wxXml2EmptyNamespace,
01058 const wxString &name = wxEmptyString,
01059 const wxString &content = wxEmptyString,
01060 wxXml2Property &props = wxXml2EmptyProperty,
01061 wxXml2Node &next = wxXml2EmptyNode,
01062 wxXml2Node &previous = wxXml2EmptyNode,
01063 wxXml2Node &children = wxXml2EmptyNode);
01064
01066 void Destroy() {
01067 xmlUnlinkNode((xmlNode *)m_obj);
01068 xmlFreeNode((xmlNode *)m_obj);
01069 SetAsEmpty();
01070 }
01071
01072
01073 public:
01074
01077 wxXml2Node() {
01078
01079
01080 m_obj = NULL;
01081 }
01082
01088 wxXml2Node(wxXml2Document &doc,
01089 const wxString &name = wxEmptyString,
01090 wxXml2Namespace &ns = wxXml2EmptyNamespace)
01091 { CreateRoot(doc, name, ns); }
01092
01094 wxXml2Node(wxXml2NodeType type,
01095 wxXml2Node &parent,
01096 const wxString &name,
01097 const wxString &content = wxEmptyString,
01098 wxXml2Namespace &ns = wxXml2EmptyNamespace)
01099 { CreateChild(type, parent, name, content, ns); }
01100
01103 wxXml2Node(wxXml2NodeType type, wxXml2Document &doc,
01104 const wxString &name = wxEmptyString,
01105 const wxString &content = wxEmptyString,
01106 wxXml2Namespace &ns = wxXml2EmptyNamespace)
01107 { CreateTemp(type, doc, name, content, ns); }
01108
01111 wxXml2Node(xmlNode *node)
01112 { m_obj = (wxXml2BaseNodeObj *)node; JustWrappedNew(); }
01113
01115 wxXml2Node(const wxXml2Node &n) : wxXml2BaseNode()
01116 { Copy(n); }
01117
01119 wxXml2Node(const wxXml2BaseNode &n)
01120 { m_obj = n.GetObj(); JustWrappedNew(); }
01121
01122 virtual ~wxXml2Node() { DestroyIfUnlinked(); }
01123
01124
01125 public:
01126
01127 bool operator==(const wxXml2Node &node) const;
01128 bool operator!=(const wxXml2Node &p) const { return !(*this == p); }
01129
01130 wxXml2Node &operator=(const wxXml2Node &n)
01131 { Copy(n); return *this; }
01132
01133
01134 public:
01135
01139
01168 void CreateRoot(wxXml2Document &doc,
01169 const wxString &name = wxEmptyString,
01170 wxXml2Namespace &ns = wxXml2EmptyNamespace,
01171 wxXml2Property &props = wxXml2EmptyProperty);
01172
01174 void CreateChild(wxXml2NodeType type,
01175 wxXml2Node &parent,
01176 const wxString &name,
01177 const wxString &content = wxEmptyString,
01178 wxXml2Namespace &ns = wxXml2EmptyNamespace,
01179 wxXml2Property &props = wxXml2EmptyProperty,
01180 wxXml2Node &next = wxXml2EmptyNode);
01181
01186 void CreateTemp(wxXml2NodeType type,
01187 wxXml2Document &doc,
01188 const wxString &name = wxEmptyString,
01189 const wxString &content = wxEmptyString,
01190 wxXml2Namespace &ns = wxXml2EmptyNamespace,
01191 wxXml2Property &props = wxXml2EmptyProperty);
01192
01194 wxXml2Node AddContainerChild(const wxString &name);
01195
01200 wxXml2Node AddTextChild(const wxString &name, const wxString &content);
01201
01203 wxXml2Node AddCommentChild(const wxString &content);
01204
01206 wxXml2Node AddCDATAChild(const wxString &content);
01207
01209 wxXml2Node AddPIChild(const wxString &name, const wxString &content);
01210
01218 wxXml2Node AddBreakLineChild(int breaklines = 1);
01219
01222 wxXml2Property AddProperty(const wxString &name, const wxString &value);
01223
01226 wxXml2Namespace AddNamespace(const wxString &prefix, const wxString &href);
01227
01229
01230
01235
01237 void AddProperty(wxXml2Property &prop);
01238
01240 void AddChild(wxXml2Node &node);
01241
01243 void AddPrevious(wxXml2Node &node);
01244
01246 void AddNext(wxXml2Node &node);
01247
01249
01250 public:
01251
01252 wxXml2Node GetParent() const
01253 { return wxXml2Node(wxXml2BaseNode::GetParent()); }
01254 wxXml2Node GetChildren() const
01255 { return wxXml2Node(wxXml2BaseNode::GetChildren()); }
01256 wxXml2Node GetFirstChild() const
01257 { return wxXml2Node(wxXml2BaseNode::GetFirstChild()); }
01258 wxXml2Node GetNext() const
01259 { return wxXml2Node(wxXml2BaseNode::GetNext()); }
01260 wxXml2Node GetPrevious() const
01261 { return wxXml2Node(wxXml2BaseNode::GetPrevious()); }
01262
01263 wxXml2Document GetDoc() const
01264 { if (GetObj()) return wxXml2Document(GetObj()->doc); return wxXml2EmptyDoc; }
01265 wxXml2Property GetProperties() const
01266 { if (GetObj()) return wxXml2Property(GetObj()->properties); return wxXml2EmptyProperty; }
01267
01268 wxXml2Namespace GetNamespace() const
01269 { if (GetObj()) return wxXml2Namespace(GetObj()->ns, (wxXml2Node &)(*this)); return wxXml2EmptyNamespace; }
01270 wxXml2Namespace GetNamespaceDecl() const
01271 { if (GetObj()) return wxXml2Namespace(GetObj()->nsDef, (wxXml2Node &)(*this)); return wxXml2EmptyNamespace; }
01272
01276 wxString GetName() const
01277 { if (GetObj()) return XML2WX(GetObj()->name); return wxEmptyString; }
01278
01282 wxString GetContent() const
01283 { if (GetObj()) return XML2WX(GetObj()->content); return wxEmptyString; }
01284
01290 wxString GetNodeContent() const
01291 {
01292 if (GetObj())
01293 {
01294 xmlChar *str = xmlNodeGetContent(GetObj());
01295 wxString ret = XML2WX(str);
01296 xmlFree(str);
01297 return ret;
01298 }
01299 return wxEmptyString;
01300 }
01301
01304 xmlNode *GetObj() const { return (xmlNode *)m_obj; }
01305
01308 bool GetPropVal(const wxString &propName, wxString *value) const;
01309
01312 wxString GetPropVal(const wxString &propName, const wxString &defaultVal) const;
01313
01315 wxXml2Node Get(const wxString &name, int n = 0) const
01316 { return Find(name, wxT(""), n); }
01317
01319 void SetName(const wxString &name)
01320 { xmlNodeSetName(GetObj(), WX2XML(name)); }
01321
01323 void SetContent(const wxString &cont)
01324 { xmlNodeSetContent(GetObj(), WX2XML(cont)); }
01325
01326 void SetProperties(const wxXml2Property &prop);
01327 void SetNamespace(wxXml2Namespace &ns);
01328
01329 public:
01330
01334
01337 bool Contains(const wxXml2Node &tofind) const
01338 { return (Find(tofind) != wxXml2EmptyNode); }
01339
01341 bool HasProp(const wxString &propName) const;
01342
01345 void MakeUpper();
01346
01349 void MakeLower();
01350
01353 bool Cmp(const wxXml2Node &node) const;
01354
01356 bool CmpNoNs(const wxXml2Node &node) const;
01357
01362 wxXml2Node Replace(const wxXml2Node &newnode);
01363
01381 wxXml2Node Find(const wxString &name,
01382 const wxString &content = wxEmptyString,
01383 int occ = 0, bool bNS = TRUE, bool recurse = TRUE) const;
01384
01391 wxXml2Node Find(const wxXml2Node &tofind, int occ = 0, bool bNS = TRUE, bool recurse = TRUE) const;
01392
01403 wxXml2Node Encapsulate(const wxString &nodename,
01404 const wxString &content = wxEmptyString,
01405 wxXml2Namespace &ns = wxXml2EmptyNamespace,
01406 wxXml2Property &props = wxXml2EmptyProperty);
01407
01409 };
01410
01411
01412
01413
01414
01415
01416
01417
01420 class WXDLLIMPEXP_WXXML2 wxNativeNewlinesFilterStream : public wxFilterOutputStream
01421 {
01422 public:
01423 wxNativeNewlinesFilterStream(wxOutputStream &tofilter)
01424 : wxFilterOutputStream(tofilter) {}
01425 virtual ~wxNativeNewlinesFilterStream() {}
01426
01427
01428 protected:
01429
01432 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
01433 };
01434
01435
01436 #if !wxCHECK_VERSION(2,7,0)
01437
01446 class WXDLLIMPEXP_WXXML2 wxStringOutputStream : public wxOutputStream
01447 {
01448 wxString m_str;
01449
01450 public:
01451 wxStringOutputStream() {}
01452 virtual ~wxStringOutputStream() {}
01453
01455 wxString GetStr() const
01456 { return m_str; }
01457
01458 protected:
01459
01462 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
01463 };
01464 #endif
01465
01466 #endif // _WX_XML2_H_