7#include "core/fxcrt/xml/cfx_xmlelement.h"
9#include "core/fxcrt/fx_extension.h"
10#include "core/fxcrt/xml/cfx_xmlchardata.h"
11#include "core/fxcrt/xml/cfx_xmldocument.h"
12#include "core/fxcrt/xml/cfx_xmltext.h"
13#include "third_party/base/check.h"
16 DCHECK(!name_.IsEmpty());
26 auto* node = doc->CreateNode<CFX_XMLElement>(name_);
27 node->attrs_ = attrs_;
32 pChild = pChild->GetNextSibling()) {
34 node->AppendLastChild(pChild
->Clone(doc
));
40 auto pos = name_.Find(L':');
41 return pos.has_value() ? name_.Last(name_.GetLength() - pos.value() - 1)
46 auto pos = name_.Find(L':');
47 return pos.has_value() ? name_.First(pos.value()) : WideString();
51 WideString attr
(L"xmlns"
);
59 auto* pElement =
static_cast<
const CFX_XMLElement*>(pNode);
60 if (!pElement->HasAttribute(attr)) {
61 pNode = pNode->GetParent();
64 return pElement->GetAttribute(attr);
72 pChild = pChild->GetNextSibling()) {
82 ByteString bsNameEncoded = name_.ToUTF8();
84 pXMLStream->WriteString(
"<");
85 pXMLStream->WriteString(bsNameEncoded.AsStringView());
87 for (
const auto& it : attrs_) {
90 pXMLStream->WriteString(
91 AttributeToString(it.first, it.second).ToUTF8().AsStringView());
94 if (!GetFirstChild()) {
95 pXMLStream->WriteString(
" />\n");
99 pXMLStream->WriteString(
">\n");
101 for (
CFX_XMLNode* pChild = GetFirstChild(); pChild;
102 pChild = pChild->GetNextSibling()) {
105 pXMLStream->WriteString(
"</");
106 pXMLStream->WriteString(bsNameEncoded.AsStringView());
107 pXMLStream->WriteString(
">\n");
111 return GetNthChildNamed(name, 0);
116 for (
auto* child = GetFirstChild(); child; child = child->GetNextSibling()) {
117 CFX_XMLElement* elem = ToXMLElement(child);
118 if (!elem || elem->name_ != name)
129 return attrs_.find(name) != attrs_.end();
133 auto it = attrs_.find(name);
134 return it != attrs_.end() ? it->second : WideString();
138 const WideString& value) {
139 attrs_[name] = value;
146WideString CFX_XMLElement::AttributeToString(
const WideString& name,
147 const WideString& value) {
148 WideString ret = L" ";
CFX_XMLText * ToXMLText(CFX_XMLNode *pNode)
void Save(const RetainPtr< IFX_RetainableWriteStream > &pXMLStream) override
WideString GetNamespacePrefix() const
WideString GetTextData() const
CFX_XMLNode * Clone(CFX_XMLDocument *doc) override
~CFX_XMLElement() override
CFX_XMLElement(const WideString &wsTag)
bool HasAttribute(const WideString &name) const
WideString GetLocalTagName() const
Type GetType() const override
WideString GetAttribute(const WideString &name) const
WideString GetNamespaceURI() const
void SetAttribute(const WideString &name, const WideString &value)
CFX_XMLElement * GetFirstChildNamed(WideStringView name) const
void RemoveAttribute(const WideString &name)
CFX_XMLElement * GetNthChildNamed(WideStringView name, size_t idx) const
virtual void Save(const RetainPtr< IFX_RetainableWriteStream > &pXMLStream)=0
virtual CFX_XMLNode * Clone(CFX_XMLDocument *doc)=0
virtual Type GetType() const =0
const WideString & GetText() const
WideString & operator+=(const WideString &str)
WideString & operator+=(const wchar_t *str)
WideString(const wchar_t *ptr)
WideString EncodeEntities() const