diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 22 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 530752e1dd..27d136305b 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -119,3 +119,25 @@ void CFX_XMLElement::Save( } pXMLStream->WriteString(ws.AsStringView()); } + +CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed( + const WideStringView& name) const { + return GetNthChildNamed(name, 0); +} + +CFX_XMLElement* CFX_XMLElement::GetNthChildNamed(const WideStringView& name, + size_t idx) const { + for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) + continue; + + CFX_XMLElement* elem = static_cast<CFX_XMLElement*>(child); + if (elem->GetName() != name) + continue; + if (idx == 0) + return elem; + + --idx; + } + return nullptr; +} diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h index e665e24a98..f713114eb7 100644 --- a/core/fxcrt/xml/cfx_xmlelement.h +++ b/core/fxcrt/xml/cfx_xmlelement.h @@ -23,6 +23,10 @@ class CFX_XMLElement : public CFX_XMLAttributeNode { std::unique_ptr<CFX_XMLNode> Clone() override; void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override; + 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; |