......
using System.Xml.Linq;
using System.Collections;
namespace YJXMLCombination
{
struct STRUCT_TRANS_MAIN
{
public string trans_type;
public string s_ent_name;
public string trans_date;
public string create_date;
public string report_user;
public string user_link;
public string if_network;
public string s_licence_no;
public string s_ent_type;
public string s_ent_address;
}
......
public class TRANS_MAIN_Collection : IEnumerable<STRUCT_TRANS_MAIN>
{
XElement xes;
public TRANS_MAIN_Collection(XElement xes)
{
this.xes = xes;
}
IEnumerator<STRUCT_TRANS_MAIN> IEnumerable<STRUCT_TRANS_MAIN>.GetEnumerator()
{
IEnumerable<XElement> elements = from xe in xes.Elements("trans_main") select xe;
STRUCT_TRANS_MAIN struct_TRANS_MAIN = new STRUCT_TRANS_MAIN();
foreach (XElement element in elements)
{
struct_TRANS_MAIN.trans_type = element.Element("trans_type").Value.ToString();
struct_TRANS_MAIN.s_ent_name = element.Element("s_ent_name").Value.ToString();
struct_TRANS_MAIN.trans_date = element.Element("trans_date").Value.ToString();
struct_TRANS_MAIN.create_date = element.Element("create_date").Value.ToString();
struct_TRANS_MAIN.report_user = element.Element("report_user").Value.ToString();
struct_TRANS_MAIN.user_link = element.Element("user_link").Value.ToString();
struct_TRANS_MAIN.if_network = element.Element("if_network").Value.ToString();
struct_TRANS_MAIN.s_licence_no = element.Element("s_licence_no").Value.ToString();
struct_TRANS_MAIN.s_ent_type = element.Element("s_ent_type").Value.ToString();
struct_TRANS_MAIN.s_ent_address = element.Element("s_ent_address").Value.ToString();
yield return struct_TRANS_MAIN;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<STRUCT_TRANS_MAIN>)this).GetEnumerator();
}
}
调用方法:
TRANS_MAIN_Collection trans_MAIN_Collection = new TRANS_MAIN_Collection(xes);
foreach (STRUCT_TRANS_MAIN struct_TRANS_MAIN in trans_MAIN_Collection)
{
......
}