xml技术来存储数据和文档是一件很容易的事情,.net framework 在它的命名空间system.xml 就提供了一种可以很方便的操作xml的类xmldocument,它使用起来非常容易,xmldocument 其实就是一个简单的树,下面我们就来看看关于 xmldocument获取第一个节点与删除root节点方法
#include "stdafx.h"
using namespace system;
using namespace system::xml;
void navigate(xmlnode ^node, int depth)
{
if (node == nullptr)
return;console::writeline(depth);
console::writeline(node->nodetype.tostring());
console::writeline(node->name);
console::writeline(node->value);if (node->attributes != nullptr)
{
for (int i = 0; i < node->attributes->count; i++)
{
console::writeline(depth+1);
console::writeline(node->attributes[i]->name);
console::writeline(node->attributes[i]->value);
}
}
navigate(node->firstchild, depth+1);
navigate(node->nextsibling, depth);
}
void main()
{
xmldocument ^doc = gcnew xmldocument();
try
{
xmlreader ^reader = xmlreader::create("..monsters.xml");
doc->load(reader);
reader->close();
xmlnode ^node = doc->firstchild;
navigate(node, 0);
}
catch (exception ^e)
{
console::writeline("error occurred: {0}", e->message);
}
}
删除root节点
#include "stdafx.h"
using namespace system;
using namespace system::xml;
using namespace system::xml::xpath;void navigate(xpathnavigator ^nav, int depth)
{
console::writeline(depth);
console::writeline(nav->nodetype.tostring());
console::writeline(nav->name);
console::writeline(nav->value);if (nav->hasattributes)
{
nav->movetofirstattribute();
do {
console::writeline(nav->name);
console::writeline(nav->value);
}
while(nav->movetonextattribute());
nav->movetoparent();
}
if (nav->movetofirstchild())
{
navigate(nav, depth+1);
nav->movetoparent();
}
if (nav->movetonext())
navigate(nav, depth);
}void main()
{
xmldocument ^doc = gcnew xmldocument();
try
{
doc->load("..monsters.xml");
xpathnavigator ^nav = doc->createnavigator();
nav->movetoroot();
navigate(nav, 0);
}
catch (exception ^e)
{
console::writeline("error occurred: {0}", e->message);
}
}
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔