• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CFX_XMLNODE_H_
8 #define CORE_FXCRT_XML_CFX_XMLNODE_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/cfx_seekablestreamproxy.h"
13 #include "core/fxcrt/retain_ptr.h"
14 
15 enum FX_XMLNODETYPE {
16   FX_XMLNODE_Unknown = 0,
17   FX_XMLNODE_Instruction,
18   FX_XMLNODE_Element,
19   FX_XMLNODE_Text,
20   FX_XMLNODE_CharData,
21 };
22 
23 struct FX_XMLNODE {
24   int32_t iNodeNum;
25   FX_XMLNODETYPE eNodeType;
26 };
27 
28 class CFX_XMLNode {
29  public:
30   enum NodeItem {
31     Root = 0,
32     Parent,
33     FirstSibling,
34     PriorSibling,
35     NextSibling,
36     LastSibling,
37     FirstNeighbor,
38     PriorNeighbor,
39     NextNeighbor,
40     LastNeighbor,
41     FirstChild,
42     LastChild
43   };
44 
45   CFX_XMLNode();
46   virtual ~CFX_XMLNode();
47 
48   virtual FX_XMLNODETYPE GetType() const;
49   virtual std::unique_ptr<CFX_XMLNode> Clone();
50 
51   int32_t CountChildNodes() const;
52   CFX_XMLNode* GetChildNode(int32_t index) const;
53   int32_t GetChildNodeIndex(CFX_XMLNode* pNode) const;
54   int32_t InsertChildNode(CFX_XMLNode* pNode, int32_t index = -1);
55   void RemoveChildNode(CFX_XMLNode* pNode);
56   void DeleteChildren();
57 
58   CFX_XMLNode* GetPath(const wchar_t* pPath,
59                        int32_t iLength = -1,
60                        bool bQualifiedName = true) const;
61 
62   int32_t GetNodeLevel() const;
63   CFX_XMLNode* GetNodeItem(CFX_XMLNode::NodeItem eItem) const;
64   bool InsertNodeItem(CFX_XMLNode::NodeItem eItem, CFX_XMLNode* pNode);
65   CFX_XMLNode* RemoveNodeItem(CFX_XMLNode::NodeItem eItem);
66 
67   void SaveXMLNode(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream);
68 
69   CFX_XMLNode* m_pParent;
70   CFX_XMLNode* m_pChild;
71   CFX_XMLNode* m_pPrior;
72   CFX_XMLNode* m_pNext;
73 };
74 
75 #endif  // CORE_FXCRT_XML_CFX_XMLNODE_H_
76