C#.NET使用Xmldocument类,递归读取xml节点,并生成树

读取XML文档并生成树

   //递归读取
        public int readChildxml(XmlNodeList xnlist, int Pnum,int Current, string Code, string type)
        {
            int result = Current;
            foreach (XmlNode one in xnlist)
            {
                // 判断是否是支节点
               // if (one.HasChildNodes && one.InnerText != one.FirstChild.InnerText)
               if(one.HasChildNodes&&one.FirstChild.NodeType!= XmlNodeType.Text)
                {
                    //是支节点
                    IF_InterfaceInfromation informat = new IF_InterfaceInfromation();
                    informat.InterfaceCode = Code;
                    informat.InterfaceName = one.Name;
                    if (result == 0)
                    {
                        informat.Target = result;
                        result++;
                    }
                    else
                    {
                        informat.Target = result;
                        informat.ParentID = Pnum;
                        result++;
                    }
                    informat.InterfaceLeaf = one.Name;
                    informat.InterfaceType = type;
                    informat.IsNode = true;
                    IF_InterfaceInfromationDAL.Insert(informat);
                    result = readChildxml(one.ChildNodes,result-1, result, Code, type);
                }
                else
                {
                    IF_InterfaceInfromation informat = new IF_InterfaceInfromation();
                    informat.InterfaceCode = Code;
                    informat.InterfaceName = one.InnerText;
                    if (result == 0)
                    {
                        informat.Target = result;
                        result++;
                    }
                    else
                    {
                        informat.Target = result;
                        informat.ParentID = Pnum;
                        result++;
                    }
                    informat.InterfaceLeaf = one.Name;
                    informat.InterfaceType = type;
                   
                    if (one.Attributes["istrue"] != null)
                    {
                        if (one.Attributes["istrue"].Value == "true")
                        {
                            informat.IsSure = true;
                        }
                    }
                    if (one.Attributes["type"] != null)
                    {
                        informat.ValueType = one.Attributes["type"].Value;
                    }
                    if (one.Attributes["Format"] != null)
                    {
                        informat.ValueFormat = one.Attributes["Format"].Value;
                    }
                    informat.IsNode = false;
                    IF_InterfaceInfromationDAL.Insert(informat);
                }
            }
            return result;
        }

数据库设计

数据项名 数据类型 数据长度 备注
ID Int 10 主键,自动增长
InterfaceCode Varchar 50 接口编号,外键
InterfaceName Varchar 50 接口关键词中文名称
Target Int 10 本身所在节点
InterfaceLeaf varchar 50 接口节点名称
InterfaceKey Varchar 200 接口关键词
DataTable varchar 50 表名
DataAttr varchar 50 字段名
IsSure bool 是否必填
ParentID Int 10 父节点
InterfaceType varchar 50 接口类型:请求或返回
IsInput bool 是否外部输入
Priority Int 10 填入优先级
DefaultInput varchar 50 默认填写值
ValueType varchar 50 字符格式
ValueFormat varchar 50 字符形式
IsNode bool 是否是层级节点

xml格式

 <Interface>
        <name>SubmitOrder</name>
        <Chinesename>下单</Chinesename>
        <Request>
            <Body>
                <timeStamp type="string" Format="yyyy-MM-dd">时间戳</timeStamp>
                <goodsId type="string" isture="true">产品编号</goodsId>
                <people type="string" isture="true">订票人数</people>
                <phone type="string" isture="true">客户电话</phone>
                <guest_name type="string" >客户姓名</guest_name>
                <identityno type="string" >客户身份证</identityno>
                <price type="string" >对外售价</price>
                <order_note type="string" >订单备注</order_note>
                <forecasttime  type="string" Format="yyyy-MM-dd">预计游玩时间</forecasttime>
                <outOrderId  type="string" isture="true">代理商订单编号</outOrderId>
                <visitPerson>
                    <person>
                        <name type="string">姓名</name>
                        <credentials type="string">身份证号</credentials>
                    </person>
                </visitPerson>
            </Body>
        </Request>
        <Return>
            <Body>
                <timeStamp type="string">时间戳</timeStamp>
                <orderId type="string">平台订单 ID</orderId>
                <outOrderId type="string">代理商订单号</outOrderId>
                <endTime type="string">有效期</endTime>
                <credence type="string">验证码</credence>
                <inCount type="string">人数</inCount>
                <status type="string">处理结果状态</status>
                <code type="string">附加错误应答码</code>
                <describe type="string">附加错误描述</describe>
            </Body>
        </Return>
    </Interface>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值