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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
12 class CXML_AttrItem : public CFX_Object
15 CFX_ByteStringL m_QSpaceName;
16 CFX_ByteStringL m_AttrName;
17 CFX_WideStringL m_Value;
19 void Empty(IFX_Allocator* pAllocator = NULL)
21 m_QSpaceName.Empty(pAllocator);
22 m_AttrName.Empty(pAllocator);
23 m_Value.Empty(pAllocator);
26 class CXML_AttrMap : public CFX_Object
37 const CFX_WideStringL* Lookup(FX_BSTR space, FX_BSTR name) const;
38 void SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocator* pAllocator = NULL);
39 void RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocator = NULL);
40 void RemoveAll(IFX_Allocator* pAllocator = NULL);
42 CXML_AttrItem& GetAt(int index) const;
43 CFX_ObjectArray<CXML_AttrItem>* m_pMap;
45 class CXML_Content : public CFX_Object
48 CXML_Content() : m_bCDATA(FALSE), m_Content() {}
53 void Empty(IFX_Allocator* pAllocator = NULL)
55 m_Content.Empty(pAllocator);
57 void Set(FX_BOOL bCDATA, FX_WSTR content, IFX_Allocator* pAllocator = NULL)
60 m_Content.Set(content, pAllocator);
63 CFX_WideStringL m_Content;
65 class CXML_Element : public CFX_Object
69 static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
71 static CXML_Element* Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
73 static CXML_Element* Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
75 CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllocator = NULL);
77 CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator = NULL);
79 CXML_Element(IFX_Allocator* pAllocator = NULL);
87 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const;
88 void GetTagName(CFX_ByteStringL &tagName, FX_BOOL bQualified = FALSE) const;
90 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const;
91 void GetNamespace(CFX_ByteStringL &nameSpace, FX_BOOL bQualified = FALSE) const;
93 CFX_ByteString GetNamespaceURI(FX_BSTR qName) const;
94 void GetNamespaceURI(FX_BSTR qName, CFX_ByteStringL &uri) const;
96 CXML_Element* GetParent() const
101 FX_DWORD CountAttrs() const
103 return m_AttrMap.GetSize();
106 void GetAttrByIndex(int index, CFX_ByteString &space, CFX_ByteString &name, CFX_WideString &value) const;
107 void GetAttrByIndex(int index, CFX_ByteStringL &space, CFX_ByteStringL &name, CFX_WideStringL &value) const;
109 FX_BOOL HasAttr(FX_BSTR qName) const;
111 FX_BOOL GetAttrValue(FX_BSTR name, CFX_WideString& attribute) const;
112 CFX_WideString GetAttrValue(FX_BSTR name) const
115 GetAttrValue(name, attr);
118 const CFX_WideStringL* GetAttrValuePtr(FX_BSTR name) const;
120 FX_BOOL GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const;
121 CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name) const
124 GetAttrValue(space, name, attr);
127 const CFX_WideStringL* GetAttrValuePtr(FX_BSTR space, FX_BSTR name) const;
129 FX_BOOL GetAttrInteger(FX_BSTR name, int& attribute) const;
130 int GetAttrInteger(FX_BSTR name) const
133 GetAttrInteger(name, attr);
137 FX_BOOL GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute) const;
138 int GetAttrInteger(FX_BSTR space, FX_BSTR name) const
141 GetAttrInteger(space, name, attr);
145 FX_BOOL GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const;
146 FX_FLOAT GetAttrFloat(FX_BSTR name) const
149 GetAttrFloat(name, attr);
153 FX_BOOL GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attribute) const;
154 FX_FLOAT GetAttrFloat(FX_BSTR space, FX_BSTR name) const
157 GetAttrFloat(space, name, attr);
161 FX_DWORD CountChildren() const;
163 enum ChildType { Invalid, Element, Content};
165 ChildType GetChildType(FX_DWORD index) const;
167 CFX_WideString GetContent(FX_DWORD index) const;
168 const CFX_WideStringL* GetContentPtr(FX_DWORD index) const;
170 CXML_Element* GetElement(FX_DWORD index) const;
172 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) const
174 return GetElement(space, tag, 0);
177 FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag) const;
179 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, int index) const;
181 FX_DWORD FindElement(CXML_Element *pChild) const;
186 void SetTag(FX_BSTR qSpace, FX_BSTR tagname);
188 void SetTag(FX_BSTR qTagName);
190 void RemoveChildren();
192 void RemoveChild(FX_DWORD index);
197 CXML_Element* m_pParent;
199 CFX_ByteStringL m_QSpaceName;
201 CFX_ByteStringL m_TagName;
203 CXML_AttrMap m_AttrMap;
205 CFX_PtrArray m_Children;
206 friend class CXML_Parser;
207 friend class CXML_Composer;