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;
namespace XXYYZZ
{
public class ReqTasklog : Header
{
public List<ReqTasklogBody> ReqTasklogBodyList;
}
public class ReqTasklogBody
{
/// <summary>
///申请编号
/// </summary>
public string Appno { get; set; }
}
}[csharp] view plaincopyprint?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XXYYZZ
{
public class RspTasklog : Header
{
public List<RspTasklogBody> rspTasklogBodyList;
}
public class RspTasklogBody
{
/// <summary>
///申请编号
/// </summary>
&n
补充:Web开发 , 其他 ,