📄 dom_element.cpp
字号:
/* $Id: dom_element.cpp,v 1.12 2003/12/22 16:51:44 mbn Exp $
**
** ClanLib Game SDK
** Copyright (C) 2003 The ClanLib Team
** For a total list of contributers see the file CREDITS.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Core/precomp.h"
#include "API/Core/XML/dom_element.h"
#include "API/Core/XML/dom_node_list.h"
#include "API/Core/XML/dom_attr.h"
#include "API/Core/XML/dom_document.h"
#include "dom_node_generic.h"
/////////////////////////////////////////////////////////////////////////////
// CL_DomElement construction:
CL_DomElement::CL_DomElement()
{
}
CL_DomElement::CL_DomElement(CL_DomDocument &doc, const std::string &tag_name)
: CL_DomNode(doc, ELEMENT_NODE)
{
impl->node_name = tag_name;
}
CL_DomElement::CL_DomElement(CL_DomNode_Generic *impl) : CL_DomNode(impl)
{
}
CL_DomElement::~CL_DomElement()
{
}
/////////////////////////////////////////////////////////////////////////////
// CL_DomElement attributes:
std::string CL_DomElement::get_tag_name() const
{
if (impl) return impl->node_name;
return std::string();
}
/////////////////////////////////////////////////////////////////////////////
// CL_DomElement operations:
bool CL_DomElement::has_attribute(const std::string &name) const
{
if (impl)
{
for(int i = 0; i < (int)impl->attributes.size(); ++i)
if (impl->attributes[i].first == name)
return true;
}
return false;
}
std::string CL_DomElement::get_attribute(const std::string &name) const
{
if (impl)
{
for(int i = 0; i < (int)impl->attributes.size(); ++i)
if (impl->attributes[i].first == name)
return impl->attributes[i].second->node_value;
}
return std::string();
}
std::string CL_DomElement::get_attribute(const std::string &name, const std::string &default_value) const
{
if (impl)
{
for(int i = 0; i < (int)impl->attributes.size(); ++i)
if (impl->attributes[i].first == name)
return impl->attributes[i].second->node_value;
}
return default_value;
}
void CL_DomElement::set_attribute(const std::string &name, const std::string &value)
{
if (impl)
{
for(int i = 0; i < (int)impl->attributes.size(); ++i)
if (impl->attributes[i].first == name)
{
impl->attributes[i].second->node_value = value;
return;
}
CL_DomAttr attr(get_owner_document(), name);
impl->attributes.push_back(std::pair<std::string, CL_DomNode_Generic*>(name, attr.impl));
attr.impl->node_value = value;
attr.impl->add_ref();
}
}
void CL_DomElement::remove_attribute(const std::string &name)
{
if (impl)
{
for(int i = 0; i < (int)impl->attributes.size(); ++i)
if (impl->attributes[i].first == name)
{
impl->attributes[i].second->release_ref();
impl->attributes.erase(impl->attributes.begin() + i);
break;
}
}
}
CL_DomNodeList CL_DomElement::get_elements_by_tag_name(const std::string &name)
{
return CL_DomNodeList();
}
std::string CL_DomElement::get_text() const
{
std::string str;
if (has_child_nodes() == false)
return str;
CL_DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_text())
str.append(cur.get_node_value());
cur = cur.get_next_sibling();
}
return str;
}
void CL_DomElement::normalize()
{
}
/////////////////////////////////////////////////////////////////////////////
// CL_DomElement implementation:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -