summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmlelement.h
blob: 394866042c2a0a958a734b9225873998e65f9f34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FXCRT_XML_CFX_XMLELEMENT_H_
#define CORE_FXCRT_XML_CFX_XMLELEMENT_H_

#include <map>
#include <memory>
#include <vector>

#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"

class CFX_XMLDocument;

class CFX_XMLElement : public CFX_XMLNode {
 public:
  explicit CFX_XMLElement(const WideString& wsTag);
  ~CFX_XMLElement() override;

  // CFX_XMLNode
  FX_XMLNODETYPE GetType() const override;
  CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
  void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override;

  WideString GetName() const { return name_; }

  const std::map<WideString, WideString>& GetAttributes() const {
    return attrs_;
  }
  bool HasAttribute(const WideString& name) const;
  void SetAttribute(const WideString& name, const WideString& value);
  WideString GetAttribute(const WideString& name) const;

  void RemoveAttribute(const WideString& name);

  CFX_XMLElement* GetFirstChildNamed(const WideStringView& name) const;
  CFX_XMLElement* GetNthChildNamed(const WideStringView& name,
                                   size_t idx) const;

  WideString GetLocalTagName() const;
  WideString GetNamespacePrefix() const;
  WideString GetNamespaceURI() const;

  WideString GetTextData() const;

 private:
  WideString AttributeToString(const WideString& name, const WideString& value);

  WideString name_;
  std::map<WideString, WideString> attrs_;
};

inline CFX_XMLElement* ToXMLElement(CFX_XMLNode* pNode) {
  return pNode && pNode->GetType() == FX_XMLNODE_Element
             ? static_cast<CFX_XMLElement*>(pNode)
             : nullptr;
}

inline const CFX_XMLElement* ToXMLElement(const CFX_XMLNode* pNode) {
  return pNode && pNode->GetType() == FX_XMLNODE_Element
             ? static_cast<const CFX_XMLElement*>(pNode)
             : nullptr;
}

#endif  // CORE_FXCRT_XML_CFX_XMLELEMENT_H_