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_XMLELEMENT_H_ 8 #define CORE_FXCRT_XML_CFX_XMLELEMENT_H_ 9 10 #include <map> 11 12 #include "core/fxcrt/fx_string.h" 13 #include "core/fxcrt/xml/cfx_xmlnode.h" 14 15 class CFX_XMLDocument; 16 17 class CFX_XMLElement final : public CFX_XMLNode { 18 public: 19 explicit CFX_XMLElement(const WideString& wsTag); 20 ~CFX_XMLElement() override; 21 22 // CFX_XMLNode 23 Type GetType() const override; 24 CFX_XMLNode* Clone(CFX_XMLDocument* doc) override; 25 void Save(const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) override; 26 GetName()27 const WideString& GetName() const { return name_; } 28 GetAttributes()29 const std::map<WideString, WideString>& GetAttributes() const { 30 return attrs_; 31 } 32 bool HasAttribute(const WideString& name) const; 33 void SetAttribute(const WideString& name, const WideString& value); 34 WideString GetAttribute(const WideString& name) const; 35 36 void RemoveAttribute(const WideString& name); 37 38 CFX_XMLElement* GetFirstChildNamed(WideStringView name) const; 39 CFX_XMLElement* GetNthChildNamed(WideStringView name, size_t idx) const; 40 41 WideString GetLocalTagName() const; 42 WideString GetNamespacePrefix() const; 43 WideString GetNamespaceURI() const; 44 45 WideString GetTextData() const; 46 47 private: 48 WideString AttributeToString(const WideString& name, const WideString& value); 49 50 const WideString name_; 51 std::map<WideString, WideString> attrs_; 52 }; 53 ToXMLElement(CFX_XMLNode * pNode)54inline CFX_XMLElement* ToXMLElement(CFX_XMLNode* pNode) { 55 return pNode && pNode->GetType() == CFX_XMLNode::Type::kElement 56 ? static_cast<CFX_XMLElement*>(pNode) 57 : nullptr; 58 } 59 ToXMLElement(const CFX_XMLNode * pNode)60inline const CFX_XMLElement* ToXMLElement(const CFX_XMLNode* pNode) { 61 return pNode && pNode->GetType() == CFX_XMLNode::Type::kElement 62 ? static_cast<const CFX_XMLElement*>(pNode) 63 : nullptr; 64 } 65 66 #endif // CORE_FXCRT_XML_CFX_XMLELEMENT_H_ 67