⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domnodes.cpp

📁 简单的xml解析类
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//************************************************************************************************************************** 
//* Blue Xml Extension
//* Copyright (c) 2002-2004 Josh Harler
//* 
//* Blue - General Purpose C++ Library
//* Copyright (c) 2002-2004 Josh Harler
//* 
//* This software is provided 'as-is', without any express or implied warranty. In no event
//* will the authors be held liable for any damages arising from the use of this software.
//* 
//* Permission is granted to anyone to use this software for any purpose, including commercial
//* applications, and to alter it and redistribute it freely, subject to the following restrictions:
//* 
//* 	1. The origin of this software must not be misrepresented; you must not claim that you
//* 	wrote the original software. If you use this software in a product, an acknowledgment in the
//* 	product documentation would be appreciated but is not required.
//* 
//* 	2. Altered source versions must be plainly marked as such, and must not be misrepresented as
//* 	being the original software.
//* 
//* 	3. This notice may not be removed or altered from any source distribution.
//*
//*
//* file   Blue/Extension/Xml/DomNodes.cpp
//**

// Private Headers =========================================================================================================

// matching header
#include "DomNodes.h"


// Private Defines/Enums/Typedefs/Etc ======================================================================================

// Private Classes/Structs =================================================================================================

// Private Global Variables ================================================================================================

// External Global Variables ===============================================================================================

// Private Functions =======================================================================================================

// Functions ===============================================================================================================

namespace blue {
namespace ext {
namespace xml {

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode::DomNode( DomNode* parent ) :m_parent(parent)
	{
		if( parent != 0 ) {
			parent->addSubNode(this);
		}
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode::~DomNode()
	{
		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			delete m_nodes[i];
		}
	}

	// ---------------------------------------------------------------------------------------------------------------------
	
	String DomNode::getPath() const
	{
		return (String::null);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode* DomNode::getParent() const
	{
		return (m_parent);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	Array<DomNode*> DomNode::getSubNodes()
	{
		return m_nodes.copy();
	}

	// ---------------------------------------------------------------------------------------------------------------------

	const Array<DomNode*> DomNode::getSubNodes() const
	{
		return m_nodes.copy();
	}

	// ---------------------------------------------------------------------------------------------------------------------

	Array<DomNode*> DomNode::getSubNodes( node_type_e type )
	{
		Array<DomNode*> nodes;
		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			if( m_nodes[i]->getNodeType() == type ) {
				nodes.append(m_nodes[i]);
			}
		}
		return (nodes);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	const Array<DomNode*> DomNode::getSubNodes( node_type_e type ) const
	{
		return ((DomNode*)this)->getSubNodes(type);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode* DomNode::getSubNode( String name )
	{
		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			if( m_nodes[i]->getName() == name ) {
				return (m_nodes[i]);
			}
		}

		return (0);
	}
	
	// ---------------------------------------------------------------------------------------------------------------------
	
	const DomNode* DomNode::getSubNode( String name ) const
	{
		return ((DomNode*)this)->getSubNode(name);
	}
	
	// ---------------------------------------------------------------------------------------------------------------------

	void DomNode::setName( String name )
	{
	}

	// ---------------------------------------------------------------------------------------------------------------------

	void DomNode::setValue( String value )
	{
	}

	// ---------------------------------------------------------------------------------------------------------------------

	void DomNode::addSubNode( DomNode* node )
	{
		m_nodes.append(node);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	void DomNode::removeSubNode( DomNode* node )
	{
		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			if( m_nodes[i] == node ) {
				delete node;
				m_nodes.remove(i);
				break;
			}
		}
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode* DomNode::copyTree( DomNode* parent )
	{
		DomNode* myClone = clone(parent);

		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			m_nodes[i]->copyTree(myClone);
		}

		return (myClone);
	}


	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------


	DomDocumentNode::DomDocumentNode() :DomNode(0)
	{
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomDocumentNode::~DomDocumentNode()
	{
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomDocumentNode::getName() const
	{
		return ($("#document"));
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomDocumentNode::getValue() const
	{
		return (String::null);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode::node_type_e DomDocumentNode::getNodeType() const
	{
		return (DomNode::DOCUMENT);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomDocumentNode::getPath() const
	{
		return (String::null);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomElementNode* DomDocumentNode::getRootElement()
	{
		for( int i = 0; i < m_nodes.getSize(); ++i ) {
			if( m_nodes[i]->getNodeType() == DomNode::ELEMENT ) {
				return ((DomElementNode*)m_nodes[i]);
			}
		}

		return (0);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	const DomElementNode* DomDocumentNode::getRootElement() const
	{
		return ((DomDocumentNode*)this)->getRootElement();
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode* DomDocumentNode::clone( DomNode* parent )
	{
		return (new DomDocumentNode());
	}


	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------
	// ---------------------------------------------------------------------------------------------------------------------


	DomElementNode::DomElementNode( DomNode* parent, String name, String text ) :DomNode(parent), m_name(name)
	{
		if( parent == 0 || (parent->getNodeType() != DomNode::DOCUMENT && parent->getNodeType() != DomNode::ELEMENT) ) {
			throw DomNodeException($("Element nodes must have either a document parent node or an element parent node"));
		}

		if( text != String::null ) {
			addText(text);
		}
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomElementNode::~DomElementNode()
	{
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomElementNode::getName() const
	{
		return (m_name);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomElementNode::getValue() const
	{
		return getTextValue();
	}

	// ---------------------------------------------------------------------------------------------------------------------

	DomNode::node_type_e DomElementNode::getNodeType() const
	{
		return (DomNode::ELEMENT);
	}

	// ---------------------------------------------------------------------------------------------------------------------

	String DomElementNode::getPath() const
	{
		String myPath = m_name;

		DomNode* parent = getParent();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -