1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_INCLUDE_FXCRT_FX_XML_H_ 8 #define CORE_INCLUDE_FXCRT_FX_XML_H_ 9 10 #include "fx_basic.h" 11 12 class CXML_AttrItem 13 { 14 public: 15 CFX_ByteString m_QSpaceName; 16 CFX_ByteString m_AttrName; 17 CFX_WideString m_Value; 18 }; 19 class CXML_AttrMap 20 { 21 public: CXML_AttrMap()22 CXML_AttrMap() 23 { 24 m_pMap = NULL; 25 } ~CXML_AttrMap()26 ~CXML_AttrMap() 27 { 28 RemoveAll(); 29 } 30 const CFX_WideString* Lookup(FX_BSTR space, FX_BSTR name) const; 31 void SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value); 32 void RemoveAt(FX_BSTR space, FX_BSTR name); 33 void RemoveAll(); 34 int GetSize() const; 35 CXML_AttrItem& GetAt(int index) const; 36 CFX_ObjectArray<CXML_AttrItem>* m_pMap; 37 }; 38 class CXML_Content 39 { 40 public: CXML_Content()41 CXML_Content() : m_bCDATA(FALSE), m_Content() {} Set(FX_BOOL bCDATA,FX_WSTR content)42 void Set(FX_BOOL bCDATA, FX_WSTR content) 43 { 44 m_bCDATA = bCDATA; 45 m_Content = content; 46 } 47 FX_BOOL m_bCDATA; 48 CFX_WideString m_Content; 49 }; 50 class CXML_Element 51 { 52 public: 53 static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); 54 static CXML_Element* Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); 55 static CXML_Element* Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); 56 CXML_Element(FX_BSTR qSpace, FX_BSTR tagName); 57 CXML_Element(FX_BSTR qTagName); 58 CXML_Element(); 59 60 ~CXML_Element(); 61 62 void Empty(); 63 64 65 66 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; 67 68 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; 69 70 CFX_ByteString GetNamespaceURI(FX_BSTR qName) const; 71 GetParent()72 CXML_Element* GetParent() const 73 { 74 return m_pParent; 75 } 76 CountAttrs()77 FX_DWORD CountAttrs() const 78 { 79 return m_AttrMap.GetSize(); 80 } 81 82 void GetAttrByIndex(int index, CFX_ByteString &space, CFX_ByteString &name, CFX_WideString &value) const; 83 84 FX_BOOL HasAttr(FX_BSTR qName) const; 85 86 FX_BOOL GetAttrValue(FX_BSTR name, CFX_WideString& attribute) const; GetAttrValue(FX_BSTR name)87 CFX_WideString GetAttrValue(FX_BSTR name) const 88 { 89 CFX_WideString attr; 90 GetAttrValue(name, attr); 91 return attr; 92 } 93 94 FX_BOOL GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const; GetAttrValue(FX_BSTR space,FX_BSTR name)95 CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name) const 96 { 97 CFX_WideString attr; 98 GetAttrValue(space, name, attr); 99 return attr; 100 } 101 102 FX_BOOL GetAttrInteger(FX_BSTR name, int& attribute) const; GetAttrInteger(FX_BSTR name)103 int GetAttrInteger(FX_BSTR name) const 104 { 105 int attr = 0; 106 GetAttrInteger(name, attr); 107 return attr; 108 } 109 110 FX_BOOL GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute) const; GetAttrInteger(FX_BSTR space,FX_BSTR name)111 int GetAttrInteger(FX_BSTR space, FX_BSTR name) const 112 { 113 int attr = 0; 114 GetAttrInteger(space, name, attr); 115 return attr; 116 } 117 118 FX_BOOL GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const; GetAttrFloat(FX_BSTR name)119 FX_FLOAT GetAttrFloat(FX_BSTR name) const 120 { 121 FX_FLOAT attr = 0; 122 GetAttrFloat(name, attr); 123 return attr; 124 } 125 126 FX_BOOL GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attribute) const; GetAttrFloat(FX_BSTR space,FX_BSTR name)127 FX_FLOAT GetAttrFloat(FX_BSTR space, FX_BSTR name) const 128 { 129 FX_FLOAT attr = 0; 130 GetAttrFloat(space, name, attr); 131 return attr; 132 } 133 134 FX_DWORD CountChildren() const; 135 136 enum ChildType { Invalid, Element, Content}; 137 138 ChildType GetChildType(FX_DWORD index) const; 139 140 CFX_WideString GetContent(FX_DWORD index) const; 141 142 CXML_Element* GetElement(FX_DWORD index) const; 143 GetElement(FX_BSTR space,FX_BSTR tag)144 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) const 145 { 146 return GetElement(space, tag, 0); 147 } 148 149 FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag) const; 150 151 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, int index) const; 152 153 FX_DWORD FindElement(CXML_Element *pChild) const; 154 155 156 157 158 void SetTag(FX_BSTR qSpace, FX_BSTR tagname); 159 160 void SetTag(FX_BSTR qTagName); 161 162 void RemoveChildren(); 163 164 void RemoveChild(FX_DWORD index); 165 166 167 protected: 168 169 CXML_Element* m_pParent; 170 CFX_ByteString m_QSpaceName; 171 CFX_ByteString m_TagName; 172 173 CXML_AttrMap m_AttrMap; 174 175 CFX_PtrArray m_Children; 176 friend class CXML_Parser; 177 friend class CXML_Composer; 178 }; 179 180 #endif // CORE_INCLUDE_FXCRT_FX_XML_H_ 181