asp.net C++输出 xml代码

作者:袖梨 2022-06-25

asp教程.net c++输出 xml代码

#include "stdafx.h"
using namespace system;
using namespace system::configuration;
using namespace system::data;
using namespace system::data::sqlclient;
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(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();

    sqlconnection ^connect = gcnew sqlconnection();
   
    connect->connectionstring = "sqlconnection";
    sqldataadapter ^dadapt = gcnew sqldataadapter();
    dataset ^dset          = gcnew dataset();
    dadapt->selectcommand  = gcnew sqlcommand("select * from authors", connect);
       
    dadapt->fill(dset, "authors");
    xmldatadocument ^doc1 = gcnew xmldatadocument(dset);

    navigate(doc1->documentelement, 0);
}


加载xml 文件到 xmldocument

#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);
    }
}

相关文章

精彩推荐