• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FXCRT_XML_CXML_ELEMENT_H_
8 #define CORE_FXCRT_XML_CXML_ELEMENT_H_
9 
10 #include <memory>
11 #include <utility>
12 #include <vector>
13 
14 #include "core/fxcrt/xml/cxml_attritem.h"
15 #include "core/fxcrt/xml/cxml_object.h"
16 
17 class CXML_Element : public CXML_Object {
18  public:
19   static std::unique_ptr<CXML_Element> Parse(const void* pBuffer, size_t size);
20 
21   CXML_Element(const CXML_Element* pParent,
22                const ByteStringView& qSpace,
23                const ByteStringView& tagname);
24   ~CXML_Element() override;
25 
26   // CXML_Object:
27   CXML_Element* AsElement() override;
28   const CXML_Element* AsElement() const override;
29 
30   ByteString GetTagName() const;
31   ByteString GetNamespaceURI(const ByteString& qName) const;
GetParent()32   const CXML_Element* GetParent() const { return m_pParent.Get(); }
CountAttrs()33   size_t CountAttrs() const { return m_AttrMap.size(); }
34   void GetAttrByIndex(size_t index,
35                       ByteString* space,
36                       ByteString* name,
37                       WideString* value) const;
38   WideString GetAttrValue(const ByteStringView& name) const;
39 
40   int GetAttrInteger(const ByteStringView& name) const;
41 
AppendChild(std::unique_ptr<CXML_Object> child)42   void AppendChild(std::unique_ptr<CXML_Object> child) {
43     m_Children.push_back(std::move(child));
44   }
45 
CountChildren()46   size_t CountChildren() const { return m_Children.size(); }
47   size_t CountElements(const ByteStringView& space,
48                        const ByteStringView& tag) const;
49   CXML_Object* GetChild(size_t index) const;
50   CXML_Element* GetElement(const ByteStringView& space,
51                            const ByteStringView& tag,
52                            size_t nth) const;
53 
54   void SetAttribute(const ByteString& space,
55                     const ByteString& name,
56                     const WideString& value);
57 
58  private:
59   static bool MatchesElement(const CXML_Element* pKid,
60                              const ByteStringView& space,
61                              const ByteStringView& tag);
62 
63   const WideString* Lookup(const ByteString& space,
64                            const ByteString& name) const;
65 
66   UnownedPtr<const CXML_Element> const m_pParent;
67   const ByteString m_QSpaceName;
68   const ByteString m_TagName;
69   std::vector<CXML_AttrItem> m_AttrMap;
70   std::vector<std::unique_ptr<CXML_Object>> m_Children;
71 };
72 
73 #endif  // CORE_FXCRT_XML_CXML_ELEMENT_H_
74