📄 domnodes.cpp
字号:
void DomAttributeNode::setValue( String value )
{
m_value = value;
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode* DomAttributeNode::clone( DomNode* parent )
{
return (new DomAttributeNode(parent, m_name, m_value));
}
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
DomTextNode::DomTextNode( DomNode* parent, String text ) :DomNode(parent)
{
if( parent == 0 || parent->getNodeType() != DomNode::ELEMENT ) {
throw DomNodeException($("A text node must have a parent element node"));
}
setValue(text);
}
// ---------------------------------------------------------------------------------------------------------------------
DomTextNode::~DomTextNode()
{
}
// ---------------------------------------------------------------------------------------------------------------------
String DomTextNode::getName() const
{
return ("#text");
}
// ---------------------------------------------------------------------------------------------------------------------
String DomTextNode::getValue() const
{
return (m_value);
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode::node_type_e DomTextNode::getNodeType() const
{
return (DomNode::TEXT);
}
// ---------------------------------------------------------------------------------------------------------------------
String DomTextNode::getPath() const
{
String myPath = getParent()->getPath() + "/text()";
const Array<DomNode*> siblings = getParent()->getSubNodes();
int count = 0, id = 0;
for( int i = 0; i < siblings.getSize(); ++i ) {
if( siblings[i]->getNodeType() == DomNode::TEXT || siblings[i]->getNodeType() == DomNode::CDATA ) {
++count;
if( siblings[i] == (DomNode*)this ) {
id = count;
break;
}
}
}
myPath += String::format("[%d]", id);
return (myPath);
}
// ---------------------------------------------------------------------------------------------------------------------
void DomTextNode::setValue( String value )
{
m_value = value;
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode* DomTextNode::clone( DomNode* parent )
{
return (new DomTextNode(parent, m_value));
}
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
DomCDataNode::DomCDataNode( DomNode* parent, String text ) :DomTextNode(parent, text)
{
if( parent == 0 || parent->getNodeType() != DomNode::ELEMENT ) {
throw DomNodeException($("A cdata node must have a parent element node"));
}
}
// ---------------------------------------------------------------------------------------------------------------------
DomCDataNode::~DomCDataNode()
{
}
// ---------------------------------------------------------------------------------------------------------------------
String DomCDataNode::getName() const
{
return ($("#cdata"));
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode::node_type_e DomCDataNode::getNodeType() const
{
return (DomNode::CDATA);
}
// ---------------------------------------------------------------------------------------------------------------------
String DomCDataNode::getPath() const
{
return DomTextNode::getPath();
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode* DomCDataNode::clone( DomNode* parent )
{
return (new DomCDataNode(parent, getValue()));
}
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
DomProcInstNode::DomProcInstNode( DomNode* parent, String instruction ) :DomNode(parent)
{
if( parent == 0 || (parent->getNodeType() != DomNode::DOCUMENT && parent->getNodeType() != DomNode::ELEMENT) ) {
throw DomNodeException($("A processing instruction node must have a parent document node"));
}
setName(instruction);
}
// ---------------------------------------------------------------------------------------------------------------------
DomProcInstNode::~DomProcInstNode()
{
}
// ---------------------------------------------------------------------------------------------------------------------
String DomProcInstNode::getName() const
{
return (m_name);
}
// ---------------------------------------------------------------------------------------------------------------------
String DomProcInstNode::getValue() const
{
return (String::null);
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode::node_type_e DomProcInstNode::getNodeType() const
{
return (DomNode::PROC_INST);
}
// ---------------------------------------------------------------------------------------------------------------------
String DomProcInstNode::getPath() const
{
String myPath = getParent()->getPath() + "/processing-instruction()";
const Array<DomNode*> siblings = getParent()->getSubNodes();
int count = 0, id = 0;
for( int i = 0; i < siblings.getSize(); ++i ) {
if( siblings[i]->getNodeType() == DomNode::PROC_INST ) {
++count;
if( siblings[i] == (DomNode*)this ) {
id = count;
break;
}
}
}
myPath += String::format("[%d]", id);
return (myPath);
}
// ---------------------------------------------------------------------------------------------------------------------
void DomProcInstNode::setName( String name )
{
m_name = name;
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode* DomProcInstNode::clone( DomNode* parent )
{
return (new DomProcInstNode(parent, m_name));
}
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------
DomCommentNode::DomCommentNode( DomNode* parent, String comment ) :DomNode(parent)
{
if( parent == 0 ) {
throw DomNodeException($("A comment node must have a parent node"));
}
setValue(comment);
}
// ---------------------------------------------------------------------------------------------------------------------
DomCommentNode::~DomCommentNode()
{
}
// ---------------------------------------------------------------------------------------------------------------------
String DomCommentNode::getName() const
{
return ($("#comment"));
}
// ---------------------------------------------------------------------------------------------------------------------
String DomCommentNode::getValue() const
{
return (m_value);
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode::node_type_e DomCommentNode::getNodeType() const
{
return (DomNode::COMMENT);
}
// ---------------------------------------------------------------------------------------------------------------------
String DomCommentNode::getPath() const
{
String myPath = getParent()->getPath() + "/comment()";
const Array<DomNode*> siblings = getParent()->getSubNodes();
int count = 0, id = 0;
for( int i = 0; i < siblings.getSize(); ++i ) {
if( siblings[i]->getNodeType() == DomNode::COMMENT ) {
++count;
if( siblings[i] == (DomNode*)this ) {
id = count;
break;
}
}
}
myPath += String::format("[%d]", id);
return (myPath);
}
// ---------------------------------------------------------------------------------------------------------------------
void DomCommentNode::setValue( String value )
{
m_value = value;
}
// ---------------------------------------------------------------------------------------------------------------------
DomNode* DomCommentNode::clone( DomNode* parent )
{
return (new DomCommentNode(parent, m_value));
}
}}} // namespaces
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -