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
7 #ifndef CORE_INCLUDE_FXCRT_FX_XML_H_
8 #define CORE_INCLUDE_FXCRT_FX_XML_H_
14 CFX_ByteString m_QSpaceName;
15 CFX_ByteString m_AttrName;
16 CFX_WideString m_Value;
20 CXML_AttrMap() { m_pMap = NULL; }
21 ~CXML_AttrMap() { RemoveAll(); }
22 const CFX_WideString* Lookup(const CFX_ByteStringC& space,
23 const CFX_ByteStringC& name) const;
24 void SetAt(const CFX_ByteStringC& space,
25 const CFX_ByteStringC& name,
26 const CFX_WideStringC& value);
27 void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name);
30 CXML_AttrItem& GetAt(int index) const;
31 CFX_ObjectArray<CXML_AttrItem>* m_pMap;
35 CXML_Content() : m_bCDATA(FALSE), m_Content() {}
36 void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) {
41 CFX_WideString m_Content;
45 static CXML_Element* Parse(const void* pBuffer,
47 FX_BOOL bSaveSpaceChars = FALSE,
48 FX_FILESIZE* pParsedSize = NULL);
49 static CXML_Element* Parse(IFX_FileRead* pFile,
50 FX_BOOL bSaveSpaceChars = FALSE,
51 FX_FILESIZE* pParsedSize = NULL);
52 static CXML_Element* Parse(IFX_BufferRead* pBuffer,
53 FX_BOOL bSaveSpaceChars = FALSE,
54 FX_FILESIZE* pParsedSize = NULL);
55 CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName);
56 CXML_Element(const CFX_ByteStringC& qTagName);
63 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const;
65 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const;
67 CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const;
69 CXML_Element* GetParent() const { return m_pParent; }
71 FX_DWORD CountAttrs() const { return m_AttrMap.GetSize(); }
73 void GetAttrByIndex(int index,
74 CFX_ByteString& space,
76 CFX_WideString& value) const;
78 FX_BOOL HasAttr(const CFX_ByteStringC& qName) const;
80 FX_BOOL GetAttrValue(const CFX_ByteStringC& name,
81 CFX_WideString& attribute) const;
82 CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const {
84 GetAttrValue(name, attr);
88 FX_BOOL GetAttrValue(const CFX_ByteStringC& space,
89 const CFX_ByteStringC& name,
90 CFX_WideString& attribute) const;
91 CFX_WideString GetAttrValue(const CFX_ByteStringC& space,
92 const CFX_ByteStringC& name) const {
94 GetAttrValue(space, name, attr);
98 FX_BOOL GetAttrInteger(const CFX_ByteStringC& name, int& attribute) const;
99 int GetAttrInteger(const CFX_ByteStringC& name) const {
101 GetAttrInteger(name, attr);
105 FX_BOOL GetAttrInteger(const CFX_ByteStringC& space,
106 const CFX_ByteStringC& name,
107 int& attribute) const;
108 int GetAttrInteger(const CFX_ByteStringC& space,
109 const CFX_ByteStringC& name) const {
111 GetAttrInteger(space, name, attr);
115 FX_BOOL GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute) const;
116 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& name) const {
118 GetAttrFloat(name, attr);
122 FX_BOOL GetAttrFloat(const CFX_ByteStringC& space,
123 const CFX_ByteStringC& name,
124 FX_FLOAT& attribute) const;
125 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space,
126 const CFX_ByteStringC& name) const {
128 GetAttrFloat(space, name, attr);
132 FX_DWORD CountChildren() const;
134 enum ChildType { Invalid, Element, Content };
136 ChildType GetChildType(FX_DWORD index) const;
138 CFX_WideString GetContent(FX_DWORD index) const;
140 CXML_Element* GetElement(FX_DWORD index) const;
142 CXML_Element* GetElement(const CFX_ByteStringC& space,
143 const CFX_ByteStringC& tag) const {
144 return GetElement(space, tag, 0);
147 FX_DWORD CountElements(const CFX_ByteStringC& space,
148 const CFX_ByteStringC& tag) const;
150 CXML_Element* GetElement(const CFX_ByteStringC& space,
151 const CFX_ByteStringC& tag,
154 FX_DWORD FindElement(CXML_Element* pChild) const;
156 void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname);
158 void SetTag(const CFX_ByteStringC& qTagName);
160 void RemoveChildren();
162 void RemoveChild(FX_DWORD index);
165 CXML_Element* m_pParent;
166 CFX_ByteString m_QSpaceName;
167 CFX_ByteString m_TagName;
169 CXML_AttrMap m_AttrMap;
171 CFX_PtrArray m_Children;
172 friend class CXML_Parser;
173 friend class CXML_Composer;
176 #endif // CORE_INCLUDE_FXCRT_FX_XML_H_