当前位置:首页 > 科技 >

xml读写文件实例

发布时间:2017-09-03 13:08:08

xml读写文件实例

在某个通讯中需要向服务器发送请求xml,站群系统,格式例子如下:
[html] view plaincopyprint?
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<HEADER>
<TRANNO>001</TRANNO>
</HEADER>
<BODY>
<BATCH>Y</BATCH>
<TASKLOG>
<APPNO>0000000001</APPNO>
</TASKLOG>
<TASKLOG>
<APPNO>0000000002</APPNO>
</TASKLOG>
</BODY>
</ROOT>

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<HEADER>
<TRANNO>001</TRANNO>
</HEADER>
<BODY>
<BATCH>Y</BATCH>
<TASKLOG>
<APPNO>0000000001</APPNO>
</TASKLOG>
<TASKLOG>
<APPNO>0000000002</APPNO>
</TASKLOG>
</BODY>
</ROOT>服务器反馈信息如下:
[html] view plaincopyprint?
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<HEADER>
<TRANNO>001</TRANNO>
</HEADER>
<BODY>
<BATCH>Y</BATCH>
<TASKLOG>
<APPNO>0000000001</APPNO>
<STATUS>001</STATUS>
</TASKLOG>
<TASKLOG>
<APPNO>0000000002</APPNO>
<STATUS>002</STATUS>
</TASKLOG>
</BODY>
</ROOT>

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<HEADER>
<TRANNO>001</TRANNO>
</HEADER>
<BODY>
<BATCH>Y</BATCH>
<TASKLOG>
<APPNO>0000000001</APPNO>
<STATUS>001</STATUS>
</TASKLOG>
<TASKLOG>
<APPNO>0000000002</APPNO>
<STATUS>002</STATUS>
</TASKLOG>
</BODY>
</ROOT>1、创建xml节点头的实体类、请求实体类、接收实体类
[csharp] view plaincopyprint?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XXYYZZ
{
public abstract class Header
{
/// <summary>
/// 交易号
/// </summary>
public string Tranno { get; set; }
/// <summary>
/// 是否批:Y是 N否
/// </summary>
public string Batch { get; set; }
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XXYYZZ
{
public abstract class Header
{
/// <summary>
/// 交易号
/// </summary>
public string Tranno { get; set; }
/// <summary>
/// 是否批:Y是 N否
/// </summary>
public string Batch { get; set; }
}
}[csharp] view plaincopyprint?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XXYYZZ
{
public class ReqTasklog : Header
{
public List<ReqTasklogBody> ReqTasklogBodyList;
}

public class ReqTasklogBody
{
/// <summary>
///申请编号
/// </summary>
public string Appno { get; set; }
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:潜江网站建设 http://qianjiang.45qun.com