ZFFramework
 
Loading...
Searching...
No Matches
ZFXml.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFXml_h_
7#define _ZFI_ZFXml_h_
8
9#include "ZFAlgorithmDef.h"
11
12/*
13 * all types:
14 * Null
15 * Element
16 * Text
17 * Comment
18 * Document
19 * Declaration
20 * DocType
21 * PI
22 * has name:
23 * Element, PI
24 * has value:
25 * Text, Comment, DocType, PI
26 * has attribute:
27 * Element, Declaration
28 * has child:
29 * Element, Document
30 *
31 * a typical xml to test:
32 <?xml type="declaration"?>
33 <!DOCTYPE TYPE "DOCTYPE">
34 <?pi ProcessingInstruction?>
35 <element0 attribute0="attribute value0">
36 <!-- here is a comment -->
37 <element1 attribute0="attribute value0" />
38 <element2 attribute0="attribute value0" attribute1="attribute value1"
39 attribute2="attribute value2" attribute3="attribute value3" />
40 <element3>text0</element3>
41 <element4><![CDATA[cdata & < > [ ] text]]></element4>
42 <element5><![CDATA[
43 cdata & < > [ ] text
44 cdata text 2
45 ]]></element5>
46 <element6>text with escaped chars: &lt; &gt; &amp; &apos; &quot;</element5>
47 <element7 attr="attr with escaped chars: &lt; &gt; &amp; &apos; &quot;" />
48 </element0>
49 */
51
52// ============================================================
53// ZFXmlType
59 ZFENUM_VALUE(Element)
61 ZFENUM_VALUE(Comment)
62 ZFENUM_VALUE(Document)
63 ZFENUM_VALUE(Declaration)
64 ZFENUM_VALUE(DocType)
71 ZFENUM_VALUE_REGISTER(Document)
72 ZFENUM_VALUE_REGISTER(Declaration)
77
78// ============================================================
83public:
86
106
107public:
112
134
135public:
137 ZFXmlOutputToken(void)
138 : xmlNewLineToken("\n")
139 , xmlIndentToken(" ")
140 , xmlDeclarationTagLeft("<?xml")
142 , xmlDocTypeTagLeft("<!DOCTYPE")
143 , xmlDocTypeTagRight(">")
144 , xmlPITagLeft("<?")
145 , xmlPITagRight("?>")
152 , xmlAttrEqualTag("=")
153 , xmlAttrQuoteTagLeft("\"")
155 , xmlTextCDATATagLeft("<![CDATA[")
156 , xmlTextCDATATagRight("]]>")
157 , xmlCommentTagLeft("<!--")
158 , xmlCommentTagRight("-->")
164 {
165 }
166 zfbool operator == (ZF_IN ZFXmlOutputToken const &ref) const;
167 zfbool operator != (ZF_IN ZFXmlOutputToken const &ref) const {
168 return !this->operator == (ref);
169 }
171};
174
175
187
188// ============================================================
189// ZFXml
190zfclassFwd _ZFP_ZFXmlPrivate;
195 // ============================================================
196public:
198 ZFXml(void);
199 ZFXml(ZF_IN const zfnullT &dummy);
200 ZFXml(ZF_IN ZFXmlType type);
201 ZFXml(ZF_IN const ZFXml &ref);
202 virtual ~ZFXml(void);
203
204 ZFXml &operator = (ZF_IN const ZFXml &ref);
205 ZFXml &operator = (ZF_IN const zfnullT &dummy);
206 inline zfbool operator == (ZF_IN const zfnullT &dummy) const {return !this->valid();}
207 inline zfbool operator != (ZF_IN const zfnullT &dummy) const {return this->valid();}
208 zfbool operator == (ZF_IN const ZFXml &ref) const;
209 inline zfbool operator != (ZF_IN const ZFXml &ref) const {return !(this->operator == (ref));}
211
212 // ============================================================
213public:
217 inline zfstring objectInfo(void) const {
218 zfstring ret;
219 this->objectInfoT(ret);
220 return ret;
221 }
222
223public:
228
229 // ============================================================
230public:
231 void _ZFP_ZFXml_xmlType(ZF_IN ZFXmlType type);
235 ZFXmlType type(void) const;
239 inline zfbool valid(void) const {
240 return (this->type() != v_ZFXmlType::e_Null);
241 }
242
243public:
256 ZFXml &name(ZF_IN const zfstring &name);
260 const zfstring &name(void) const;
261
274 ZFXml &value(ZF_IN const zfstring &value);
278 const zfstring &value(void) const;
279
280 // ============================================================
281public:
287 ZFXml copy(void) const;
288
289 // ============================================================
290public:
294 zfindex attrCount(void) const;
298 ZFXml &attr(
299 ZF_IN const zfstring &key
300 , ZF_IN const zfstring &value
301 );
305 zfstring attr(ZF_IN const zfstring &key) const;
309 zfbool attrExist(ZF_IN const zfstring &key) const;
313 ZFXml &attrRemove(ZF_IN const zfstring &key);
317 ZFXml &attrRemoveAll(void);
318
319public:
321 zfiter attrIter(void) const;
328
331 ZF_IN_OUT zfiter &it
332 , ZF_IN const zfstring &value
333 );
336
337 // ============================================================
338public:
342 zfindex childCount(void) const;
346 ZFXml childAt(ZF_IN zfindex index) const;
350 ZFXml &child(
351 ZF_IN const ZFXml &item
352 , ZF_IN_OPT zfindex index = zfindexMax()
353 );
361 ZFXml &childRemoveAll(void);
365 zfindex childFind(ZF_IN const ZFXml &item) const;
366
370 ZFXml childElement(void) const;
374 ZFXml childElementAt(ZF_IN zfindex index) const;
375
376 // ============================================================
377public:
385 zfbool CDATA(void) const;
386
387 // ============================================================
388 // quick access
389public:
391 inline operator zfstring (void) const {return this->toString();}
393 inline operator zfbool (void) const {return this->valid();}
395 inline zfstring operator [] (ZF_IN const zfchar *key) const {return this->attr(key);}
397 inline zfstring operator [] (ZF_IN const zfstring &key) const {return this->attr(key);}
399 inline ZFXml operator [] (ZF_IN zfindex index) const {return this->childAt(index);}
400
403
404private:
405 _ZFP_ZFXmlPrivate *d;
406private:
407 ZFXml(ZF_IN _ZFP_ZFXmlPrivate *ref);
408};
411ZFOUTPUT_TYPE(ZFXml, {v.objectInfoT(s);})
412
415 , ZFMP_IN(const zfstring &, name)
419 , ZFMP_IN(const zfstring &, value)
423 , ZFMP_IN(const zfstring &, value)
431 , ZFMP_IN(const zfstring &, value)
435 , ZFMP_IN(const zfstring &, name)
436 , ZFMP_IN(const zfstring &, value)
438
439// ============================================================
444 , ZFMP_IN(const ZFInput &, callback)
445 , ZFMP_OUT_OPT(zfstring *, errorHint, zfnull)
447
448// ============================================================
456 , ZFMP_IN_OUT(const ZFOutput &, output)
457 , ZFMP_IN(const ZFXml &, xmlItem)
467 , ZFMP_IN_OUT(zfstring &, ret)
468 , ZFMP_IN(const ZFXml &, xmlItem)
469 , ZFMP_IN(const ZFXmlOutputToken &, token)
473 , ZFMP_IN(const ZFXml &, xmlItem)
474 , ZFMP_IN(const ZFXmlOutputToken &, token)
476
477// ============================================================
478// escape chars
494 , ZFMP_OUT(zfstring &, dst)
495 , ZFMP_IN(const zfchar *, src)
497 )
502 , ZFMP_OUT(const ZFOutput &, dst)
503 , ZFMP_IN(const zfchar *, src)
505 )
506
511 , ZFMP_OUT(zfstring &, dst)
512 , ZFMP_IN(const zfchar *, src)
514 )
519 , ZFMP_OUT(const ZFOutput &, dst)
520 , ZFMP_IN(const zfchar *, src)
522 )
523
525#endif // #ifndef _ZFI_ZFXml_h_
526
global header for ZFAlgorithm module
#define ZFLIB_ZFAlgorithm
used to export symbols
Definition ZFAlgorithmDef.h:14
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
#define zfnullT
type for zfnull, can be used for function overload
Definition ZFCoreTypeDef_CoreType.h:85
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFENUM_SEPARATOR()
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:158
#define ZFENUM_VALUE_REGISTER(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:168
#define ZFENUM_REG(ZFLIB_, EnumName,...)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:186
#define ZFENUM_VALUE(Value)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:151
#define ZFENUM_BEGIN(ZFLIB_, EnumName)
macros to define reflectable enum type
Definition ZFEnumDeclare.h:147
#define ZFENUM_END(ZFLIB_, EnumName)
see ZFENUM_BEGIN
Definition ZFEnumDeclare.h:172
#define ZFEXPORT_VAR_DECLARE(ZFLIB_, Type, Name)
util to export global variable
Definition ZFExport.h:68
#define ZFMP_IN_OUT(ParamType, paramName)
see ZFMP_IN
Definition ZFMethod.h:117
#define ZFMP_OUT(ParamType, paramName)
see ZFMP_IN
Definition ZFMethod.h:111
#define ZFMP_OUT_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:114
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_FUNC_DECLARE_2(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:763
#define ZFMETHOD_FUNC_DECLARE_3(ZFLIB_, ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:910
#define ZFMETHOD_FUNC_DECLARE_0(ZFLIB_, ReturnType, MethodName)
declare function type of ZFMethod
Definition ZFMethodFuncDeclare.h:493
#define ZFMETHOD_FUNC_DECLARE_1(ZFLIB_, ReturnType, MethodName, ZFMP_0)
see ZFMETHOD_FUNC_DECLARE_0
Definition ZFMethodFuncDeclare.h:624
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define ZFTYPEID_DECLARE(ZFLIB_, TypeName, Type)
register a type for reflection
Definition ZFTypeIdDeclare.h:137
#define ZFTYPEID_ACCESS_ONLY_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:205
#define ZFTYPEID_ACCESS_ONLY_DECLARE(ZFLIB_, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:195
#define ZFTYPEID_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:151
ZFLIB_ZFAlgorithm void ZFXmlEscapeCharEncode(zfstring &dst, const zfchar *src, zfindex count=(((zfindex) -1)))
encode xml chars, e.g. convert "&" to "&"
ZFXmlOutputToken & ZFXmlOutputTokenTrim(void)
xml output token with trim format
Definition ZFXml.h:178
ZFXmlOutputToken & ZFXmlOutputTokenDetail(void)
xml output token with detailed format
Definition ZFXml.h:182
ZFXmlOutputToken & ZFXmlOutputTokenDefault(void)
default xml output token
Definition ZFXml.h:186
ZFLIB_ZFAlgorithm void ZFXmlEscapeCharDecode(zfstring &dst, const zfchar *src, zfindex count=(((zfindex) -1)))
see ZFXmlEscapeCharEncode
ZFLIB_ZFAlgorithm ZFXml ZFXmlDeclaration()
util to create ZFXml
ZFLIB_ZFAlgorithm ZFXml ZFXmlComment(const zfstring &value)
util to create ZFXml
ZFLIB_ZFAlgorithm zfbool ZFXmlToOutput(const ZFOutput &output, const ZFXml &xmlItem, const ZFXmlOutputToken &token=(ZFXmlOutputTokenDefault()))
convert xml to output
ZFLIB_ZFAlgorithm ZFXml ZFXmlDocType(const zfstring &value)
util to create ZFXml
ZFLIB_ZFAlgorithm ZFXml ZFXmlPI(const zfstring &name, const zfstring &value)
util to create ZFXml
ZFLIB_ZFAlgorithm ZFXml ZFXmlDocument()
util to create ZFXml
ZFLIB_ZFAlgorithm zfbool ZFXmlToStringT(zfstring &s, _ZFP_PropTypeW_ZFXml const &v, zfstring *errorHint=zft_zfnull)
util method to convert ZFXml to string
ZFLIB_ZFAlgorithm ZFXml ZFXmlText(const zfstring &value)
util to create ZFXml
zfstring ZFXmlToString(_ZFP_PropTypeW_ZFXml const &v, zfstring *errorHint=zft_zfnull)
util method to convert ZFXml to string
Definition ZFXml.h:409
ZFLIB_ZFAlgorithm ZFXml ZFXmlElement(const zfstring &name)
util to create ZFXml
ZFLIB_ZFAlgorithm ZFXml ZFXmlFromInput(const ZFInput &callback, zfstring *errorHint=(zft_zfnull))
parse xml document, or return an item with null type if fail
v_ZFXmlType::ZFEnumType ZFXmlType
see v_ZFXmlType
Definition ZFXml.h:75
general input callback
Definition ZFIOCallback_input.h:37
general output callback
Definition ZFIOCallback_output.h:37
xml item that holds the xml DOM
Definition ZFXml.h:194
ZFXml childElement(void) const
util to get first element child
ZFXml copy(void) const
return a copy of this node as well as all of its children
zfbool valid(void) const
true if type is v_ZFXmlType::e_Null
Definition ZFXml.h:239
zfindex childCount(void) const
child count
zfindex attrCount(void) const
get attr count
zfbool CDATA(void) const
see CDATA
zfiter attrIterFind(const zfstring &key) const
see zfiter
ZFXml & childRemoveAt(zfindex index)
remove child
zfstring attrIterKey(const zfiter &it) const
see zfiter
ZFXml & attr(const zfstring &key, const zfstring &value)
add or set attribute
zfbool attrExist(const zfstring &key) const
true if attribute exist
void attrIterValue(zfiter &it, const zfstring &value)
see zfiter
ZFXml & child(const ZFXml &item, zfindex index=((zfindex) -1))
add child at index
zfstring attrIterValue(const zfiter &it) const
see zfiter
zfstring toString(const ZFXmlOutputToken &token=ZFXmlOutputTokenDefault()) const
return ZFXmlToString
const zfstring & name(void) const
see name
zfstring attr(const zfstring &key) const
get attribute with key
zfstring objectInfo(void) const
return object info
Definition ZFXml.h:217
ZFXml & attrRemoveAll(void)
remove all attribute
ZFXml & attrRemove(const zfstring &key)
remove attribute with key
void attrIterRemove(zfiter &it)
see zfiter
ZFXml & childRemoveAll(void)
remove all child
const zfstring & value(void) const
see value
void objectInfoT(zfstring &ret) const
see objectInfo
ZFXml childElementAt(zfindex index) const
util to try get element at index
ZFXml & name(const zfstring &name)
name of the node
zfiter attrIter(void) const
see zfiter
void CDATA(zfbool CDATA)
CDATA or not, for v_ZFXmlType::e_Text.
zfindex childFind(const ZFXml &item) const
find child
ZFXml childAt(zfindex index) const
get child at index
ZFXmlType type(void) const
type of this item
ZFXml & value(const zfstring &value)
value of the node
zfindex objectRetainCount(void) const
get current retain count
token used to output a xml document
Definition ZFXml.h:82
zfstring xmlElementSingleTagRight
"/>" by default
Definition ZFXml.h:98
zfstring xmlCommentTagLeft
"<!--" by default
Definition ZFXml.h:104
zfbool xmlElementTrimTagIfNoChildren
trim "<element></element>" to "<element/>" if no children, zffalse by default
Definition ZFXml.h:128
zfstring xmlElementEndTagRight
">" by default
Definition ZFXml.h:96
zfstring xmlElementBeginTagRight
">" by default
Definition ZFXml.h:94
zfstring xmlNewLineToken
"\n" by default
Definition ZFXml.h:84
zfstring xmlDocTypeTagLeft
"<!DOCTYPE" by default
Definition ZFXml.h:89
zfstring xmlPITagLeft
"<?" by default
Definition ZFXml.h:91
zfstring xmlIndentToken
" " by default
Definition ZFXml.h:85
zfstring xmlElementBeginTagLeft
"<" by default
Definition ZFXml.h:93
zfstring xmlAttrQuoteTagLeft
"\"" by default
Definition ZFXml.h:100
zfstring xmlDeclarationTagLeft
"<?xml" by default
Definition ZFXml.h:87
zfindex xmlElementAttrCountBeforeAddNewLine
how many attributes before add new line, 3 by default
Definition ZFXml.h:120
zfstring xmlDocTypeTagRight
">" by default
Definition ZFXml.h:90
zfstring xmlTextCDATATagRight
"]]>" by default
Definition ZFXml.h:103
zfstring xmlCommentTagRight
"-->" by default
Definition ZFXml.h:105
zfstring xmlDeclarationTagRight
"?>" by default
Definition ZFXml.h:88
zfstring xmlElementSingleTagLeft
"<" by default
Definition ZFXml.h:97
zfbool xmlElementEndTagAtSameLineIfNoChildElement
whether put element's end tag in a same line if no child element or only text children,...
Definition ZFXml.h:133
zfbool xmlElementAddNewLineAtHeadIfNotSingleLine
add new line before entering a element if the element isn't single line, zffalse by default
Definition ZFXml.h:124
zfstring xmlTextCDATATagLeft
"<![CDATA[" by default
Definition ZFXml.h:102
zfstring xmlElementEndTagLeft
"</" by default
Definition ZFXml.h:95
zfstring xmlGlobalLineBeginToken
strings added to head of each new line, empty by default
Definition ZFXml.h:111
zfstring xmlAttrQuoteTagRight
"\"" by default
Definition ZFXml.h:101
zfstring xmlPITagRight
"?>" by default
Definition ZFXml.h:92
zfstring xmlAttrEqualTag
"=" by default
Definition ZFXml.h:99
@ e_Null
Definition ZFXml.h:58
iterator for ZFFramework
Definition zfiter.h:40