00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 #ifndef INC_MI32_XML_H
00135 #define INC_MI32_XML_H
00136
00137 #if 1 || defined(MISYSTEMDLL)
00138
00139
00140 #ifndef __XML_TREE_H__ // libxml's include guards, not ours
00141 #include <libxml/tree.h>
00142 #endif
00143 #ifndef __XML_PARSER_H__
00144 #include <libxml/parser.h>
00145 #endif
00146
00147 #else
00148
00149 struct xmlSAXHandler;
00150 struct _xmlNs;
00151 struct _xmlNode;
00152 struct _xmlDoc;
00153 struct _xmlEntity;
00154 typedef unsigned char xmlChar;
00155 typedef _xmlDoc* xmlDocPtr;
00156 typedef _xmlEntity* xmlEntityPtr;
00157
00158 #endif
00159
00160 #ifndef INC_MI32_MISTRING_H
00161 #include <mi32/mistring.h>
00162 #endif
00163
00164 #ifndef INC_MI32_SIMPLEAR_H
00165 #include <mi32/simplear.h>
00166 #endif
00167
00168 #ifndef GENERATING_DOXYGEN_OUTPUT
00169 class STRUTF8;
00170 #endif // GENERATING_DOXYGEN_OUTPUT
00171
00172 #ifdef MISYSTEMDLL
00173 #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00174 #else
00175 #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00176 #endif
00177
00178 #ifndef XML_CASE_SENSITIVE
00179 #define XML_CASE_SENSITIVE true
00180 #endif
00181
00182 class XMLDOC;
00183 class FILE_RAW;
00184 class FILEPATH;
00185
00186
00187 class XMLNAMESPACE
00188 #if 1 || defined(MISYSTEMDLL)
00189 : public _xmlNs
00190 #endif
00191 {
00192 public:
00193 const char* GetHREF() const { return (reinterpret_cast<const char*>(this->href)); }
00194
00197 const char* GetPrefix() const { return (reinterpret_cast<const char*>(this->prefix)); }
00198
00200 XMLNAMESPACE* Copy() { return (static_cast<XMLNAMESPACE*>(xmlCopyNamespace(this))); }
00201
00206 void Free() { xmlFreeNs(this); }
00207
00208 private:
00209 #ifndef GENERATING_DOXYGEN_OUTPUT
00212 XMLNAMESPACE();
00213 XMLNAMESPACE(const XMLNAMESPACE&);
00214 ~XMLNAMESPACE();
00215
00216 friend struct _xmlNs;
00217 #endif // GENERATING_DOXYGEN_OUTPUT
00218 };
00219
00224 class CLASSLIBEXPORT XMLNODE
00225 #if 1 || defined(MISYSTEMDLL)
00226 : public _xmlNode
00227 #endif
00228 {
00229 public:
00230
00232 void AddComment (
00233 const MIUNICODE*
00234 );
00235
00237 void AppendText (
00238 const MIUNICODE* text
00239 );
00240
00247 void Attach (
00248 XMLNODE* parent
00249 );
00250
00256 XMLNODE* Copy (
00257 bool recursive = true,
00258 XMLDOC* NewDoc = NULL
00259 ) const;
00260
00262 void Delete ();
00263
00265 void DeleteAllChildren();
00266
00271 void Detach();
00272
00274 XMLNODE* FindChild (
00275 const char *TagName
00276 ) const;
00277
00279 XMLNODE* FindChild (
00280 const char *TagName,
00281 const char *PropertyName,
00282 const MIUNICODE* PropertyValue
00283 ) const;
00284
00286 XMLNODE* FindChild (
00287 const char *TagName,
00288 const char *PropertyName,
00289 const char *PropertyValue
00290 ) const;
00291
00293 XMLNODE* FindNext (
00294 const char *TagName = 0,
00295 const char *PropName = 0,
00296 const char *PropValue = 0
00297 ) const;
00298
00299
00300
00301 bool GetContentXML (
00302 MISTRING& retstr,
00303 bool bIncludeSelf,
00304 bool bFormat = true,
00305 int indent = 0
00306 );
00307
00308
00309 bool GetContentXML (
00310 STRUTF8& retstr,
00311 bool bIncludeSelf,
00312 bool bFormat = true,
00313 int indent = 0
00314 );
00315
00318 XMLNODE* GetElementByAttribute (
00319 const char *AttributeName,
00320 const MIUNICODE* AttributeValue
00321 ) const;
00322
00325 XMLNODE* GetElementByAttribute (
00326 const char *AttributeName,
00327 const char *AttributeValue
00328 ) const;
00329
00333 bool GetElementsByTagName (
00334 SIMPLE_ARRAY<XMLNODE*>& Nodes,
00335 const char *TagName,
00336 bool bCaseSensitive = true
00337 ) const;
00338
00340 XMLNODE* GetFirstChild (
00341 ) const;
00342
00344 XMLNODE* GetLastChild () const;
00345
00347 XMLNODE* GetParent () const;
00348
00350 XMLNODE* GetPrevious () const;
00351
00356 const char* GetName () const;
00357
00359 XMLNODE* GetNext() const;
00360
00364 bool GetProperty (
00365 const char *PropName,
00366 MISTRING& str,
00367 bool bCaseSensitive = true
00368 ) const;
00369
00373 bool GetProperty (
00374 const char *PropName,
00375 STRUTF8& retstr,
00376 bool bCaseSensitive = true
00377 ) const;
00378
00384 bool GetProperty (
00385 const char *PropName,
00386 bool& retvalue,
00387 bool bCaseSensitive = true
00388 ) const;
00389
00393 bool GetProperty (
00394 const char *PropName,
00395 double& retvalue,
00396 bool bCaseSensitive = true
00397 ) const;
00398
00402 bool GetProperty (
00403 const char *PropName,
00404 INT32& retvalue,
00405 bool bCaseSensitive = true
00406 ) const;
00407
00411 bool GetProperty (
00412 const char *PropName,
00413 UINT32& retvalue,
00414 bool bCaseSensitive = true
00415 ) const;
00416
00420 bool GetProperty (
00421 const char *PropName,
00422 INT64& retvalue,
00423 bool bCaseSensitive = true
00424 ) const;
00425
00429 bool GetProperty (
00430 const char *PropName,
00431 UINT64& retvalue,
00432 bool bCaseSensitive = true
00433 ) const;
00434
00439 bool GetPropertyBool (
00440 const char *PropName,
00441 bool dft = false,
00442 bool bCaseSensitive = true
00443 ) const;
00444
00446 double GetPropertyNum (
00447 const char *PropName,
00448 double dft = 0.0,
00449 bool bCaseSensitive = true
00450 ) const;
00451
00452 #if defined(MISYSTEMDLL)
00453 #ifndef GENERATING_DOXYGEN_OUTPUT
00454
00455
00456
00459 bool GetText (
00460 MISTRING& str
00461 ) const;
00462
00465 bool GetText (
00466 STRUTF8& str
00467 ) const;
00468
00471 bool GetText (
00472 MISTRING& str,
00473 bool bPreserveLeadingAndTrailingWhitespace
00474 ) const;
00475
00478 bool GetText (
00479 STRUTF8& str,
00480 bool bPreserveLeadingAndTrailingWhitespace
00481 ) const;
00482 #endif
00483 #else
00486 bool GetText (
00487 MISTRING& str,
00488 bool bStripLeadingAndTrailingWhitespace = true
00489 ) const;
00490
00493 bool GetText (
00494 STRUTF8& str,
00495 bool bStripLeadingAndTrailingWhitespace = true
00496 ) const;
00497 #endif
00498
00504 bool GetValue (
00505 bool& retvalue
00506 ) const;
00507
00511 bool GetValue (
00512 double& retvalue
00513 ) const;
00514
00518 bool GetValue (
00519 INT32& retvalue
00520 ) const;
00521
00525 bool GetValue (
00526 UINT32& retvalue
00527 ) const;
00528
00531 bool GetValue (
00532 INT64& retvalue
00533 ) const;
00534
00537 bool GetValue (
00538 UINT64& retvalue
00539 ) const;
00540
00545 bool HasProperty (
00546 const char* name,
00547 bool bCaseSensitive=true
00548 ) const;
00549
00551 bool IsCDATA() const;
00552
00554 bool IsEmpty() const;
00555
00557 bool IsText() const;
00558
00560 XMLNODE* NewChild (
00561 const char *TagName,
00562 XMLNAMESPACE *pNameSpace = 0
00563 );
00564
00568 XMLNODE* NewChild (
00569 const char *TagName,
00570 const MIUNICODE *value,
00571 XMLNAMESPACE *pNameSpace = 0
00572 );
00573
00575 XMLNODE* NewChild (
00576 const char *TagName,
00577 double value,
00578 MISTRING::FLOATFMT floatfmt = MISTRING::FLOATFMT_MaxPrecision,
00579 XMLNAMESPACE *pNameSpace = 0
00580 );
00581
00584 XMLNODE* NewChild (
00585 const XMLNODE *NodeToCopy
00586 );
00587
00596 XMLNODE* NewCDATAChild (
00597 const char *TagName,
00598 const MIUNICODE *value,
00599 XMLNAMESPACE *pNameSpace = 0
00600 );
00601
00606 XMLNODE* NewCDATAChild (
00607 const char *TagName,
00608 const UINT8 *value,
00609 int len = -1,
00610 XMLNAMESPACE *pNameSpace = 0
00611 );
00612
00619 XMLNODE* NewTextChild (
00620 const char *TagName,
00621 const MIUNICODE *value,
00622 XMLNAMESPACE *pNameSpace = 0
00623 );
00624
00631 XMLNODE* NewTextChild (
00632 const char *TagName,
00633 const char *value,
00634 XMLNAMESPACE *pNameSpace = 0
00635 );
00636
00640 void Replace (
00641 XMLNODE* NodeToReplace
00642 );
00643
00648 void SetName(
00649 const char* name
00650 );
00651
00653 void SetNamespace (
00654 XMLNAMESPACE *pNameSpace
00655 );
00656
00660 void SetProperty (
00661 const char *PropName,
00662 const MIUNICODE *value
00663 );
00664
00668 void SetProperty (
00669 const char *PropName,
00670 const char *value
00671 );
00672
00674 void SetProperty (
00675 const char *PropName,
00676 double value,
00677 MISTRING::FLOATFMT floatfmt = MISTRING::FLOATFMT_MaxPrecision
00678 );
00679
00681 void SetText (
00682 const MIUNICODE* text
00683 );
00684
00686 void SetText (
00687 const char* text
00688 );
00689
00691 void UnsetProperty (
00692 const char *PropName
00693 );
00694
00695 private:
00696 #ifndef GENERATING_DOXYGEN_OUTPUT
00697
00700 XMLNODE();
00701 XMLNODE(const XMLNODE&);
00702 ~XMLNODE();
00703
00705 XMLNODE& operator= (
00706 const XMLNODE&
00707 );
00708
00709 friend struct _xmlNode;
00710
00714 bool GetElementsByTagNameSub (
00715 SIMPLE_ARRAY<XMLNODE*>& Nodes,
00716 const char *TagName,
00717 bool bCaseSensitive = true
00718 ) const;
00719
00722 #endif // GENERATING_DOXYGEN_OUTPUT
00723 };
00724
00725
00726 class CLASSLIBEXPORT XMLDOC {
00727 public:
00728
00729
00731 XMLDOC();
00732
00738 XMLDOC (
00739 const MIUNICODE* xmlbuffer
00740 );
00741
00744 XMLDOC (
00745 const UINT8* xmlbuffer
00746 );
00747
00751 XMLDOC (
00752 const XMLDOC&
00753 );
00754
00756 virtual ~XMLDOC();
00757
00761 XMLDOC& operator= (
00762 const XMLDOC&
00763 );
00764
00768 void AddEntity (
00769 const char* name,
00770 const MIUNICODE* content
00771 );
00772
00776 void AddEntity (
00777 const char* name,
00778 MIUNICODE content
00779 );
00780
00782 void Clear();
00783
00786 const MISTRING& GetErrorMessage (
00787 ) const;
00788
00792 ERRVALUE ReadHTML (
00793 const FILEPATH& filepath
00794 );
00795
00799 ERRVALUE ReadHTML (
00800 const MIUNICODE* filename
00801 );
00802
00805 ERRVALUE Read (
00806 const FILEPATH& filepath
00807 );
00808
00811 ERRVALUE Read (
00812 const MIUNICODE* filename
00813 );
00814
00817 ERRVALUE Parse (
00818 const UINT8* xmlbuffer
00819 );
00820
00824 ERRVALUE ParseHTML (
00825 const UINT8* xmlbuffer
00826 );
00827
00828 void SetCompression(
00829 int compression
00830 );
00831
00833 void Unparse (
00834 MISTRING& string,
00835 bool bIndentTreeOutput = true
00836 ) const;
00837
00839 void Unparse (
00840 STRUTF8& string,
00841 bool bIndentTreeOutput = true
00842 ) const;
00843
00845 void UnparseHTML (
00846 MISTRING& string,
00847 bool bIndentTreeOutput = true
00848 ) const;
00849
00851 void UnparseHTML (
00852 STRUTF8& string,
00853 bool bIndentTreeOutput = true
00854 ) const;
00855
00858 ERRVALUE Write (
00859 const FILEPATH& filepath
00860 ) const;
00861
00864 ERRVALUE Write (
00865 const MIUNICODE* filename
00866 ) const;
00867
00871 ERRVALUE Write (
00872 FILE_RAW& file
00873 ) const;
00874
00877 ERRVALUE WriteHTML (
00878 const FILEPATH& filepath
00879 ) const;
00880
00883 ERRVALUE WriteHTML (
00884 const MIUNICODE* filename
00885 ) const;
00886
00891 ERRVALUE WriteHTML (
00892 FILE_RAW& file
00893 ) const;
00894
00895 xmlDocPtr* GetDocPtr() const;
00896
00898 XMLNODE* GetRootNode (
00899 ) const;
00900
00901 protected:
00904 virtual void OnDocReplaced();
00905
00906 private:
00907 #ifndef GENERATING_DOXYGEN_OUTPUT
00908
00909 class ERRORTRAP {
00910 public:
00911 ERRORTRAP(XMLDOC*);
00912 ~ERRORTRAP();
00913 private:
00914 MISTRING& m_string;
00915
00916 static void MyErrorFunc(void*, const char*, ...);
00917 };
00918
00919 xmlDocPtr m_doc;
00920 MISTRING m_ErrorMessage;
00921
00922 friend class XMLNODE;
00923 friend class ERRORTRAP;
00924 #endif // GENERATING_DOXYGEN_OUTPUT
00925
00926 };
00927
00928
00929
00930
00937 class CLASSLIBEXPORT XMLSAX {
00938 public:
00939
00940 struct ATTRIBUTE {
00941 const xmlChar* name;
00942 const xmlChar *value;
00943 };
00944
00945
00946 XMLSAX();
00947 virtual ~XMLSAX();
00948
00950 ERRVALUE Parse (
00951 const FILEPATH& filepath
00952 );
00953
00955 ERRVALUE Parse (
00956 const char* buffer,
00957 int size
00958 );
00959
00960 private:
00961
00963 virtual void v_StartDocument ();
00964
00966 virtual void v_EndDocument ();
00967
00970 virtual void v_CDATABlock (
00971 const xmlChar* data,
00972 int len
00973 );
00974
00978 virtual void v_Characters (
00979 const xmlChar* ch,
00980 int len
00981 );
00982
00986 virtual void v_Comment (
00987 const xmlChar* ch
00988 );
00989
00992 virtual void v_IgnorableWhitespace (
00993 const xmlChar* ch,
00994 int len
00995 );
00996
01000 virtual void v_StartElement (
01001 const xmlChar* name,
01002 const SIMPLE_ARRAY<ATTRIBUTE>& attributes
01003 );
01004
01006 virtual void v_EndElement (
01007 const xmlChar* name
01008 );
01009
01010
01011 #ifndef GENERATING_DOXYGEN_OUTPUT
01012
01013 xmlSAXHandler* m_sax;
01014 SIMPLE_ARRAY<ATTRIBUTE>* m_attribs;
01015 MISTRING m_errormsg;
01016
01017
01018
01019
01020 static void startDocument(void*);
01021 static void endDocument(void*);
01022 static void characters(void*, const xmlChar*, int);
01023 static void startElement(void*, const xmlChar*, const xmlChar**);
01024 static void endElement(void*, const xmlChar*);
01025 static xmlEntityPtr getEntity(void*, const xmlChar*);
01026 static void MyErrorFunc(void*, const char*, ...);
01027 static void cdataBlock(void*, const xmlChar*, int);
01028 static void comment(void*, const xmlChar*);
01029 static void ignorableWhitespace(void*, const xmlChar*, int);
01030
01031 #endif
01032 };
01033
01034
01035
01036 #undef CLASSLIBEXPORT
01037
01038 #endif
01039