读取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>