110,538
社区成员
发帖
与我相关
我的任务
分享
1.学科表[Subject](sub_id,subName),
2.版本表[Edition](edi_id,ediName),
3.学科版本关系表[sub_edi_rel](ser_id,sub_id,edi_id),--关系表ID,学科ID,版本ID(因为学科和版本是同级,所以..)
4.册表[Volume](vol_id,volName,),
5.章表[Chapter](cha_id,chaName,vol_id),
6.节表[Section](sec_id,secName,cha_id)
with name as ()
void Test()
{
List<Subject> Subjects = new List<Subject>() {
new Subject(){SubID="1",SubName="小学语文"},
new Subject(){SubID="2",SubName="小学数学"},
new Subject(){SubID="3",SubName="中学语文"},
new Subject(){SubID="4",SubName="中学物理"},
};//怎么取数据略
List<Edition> Editions = new List<Edition>() {
new Edition(){EdiID="1",EdiName="苏教国标版"},
new Edition(){EdiID="2",EdiName="苏教版"},
new Edition(){EdiID="3",EdiName="人教版"},
};//怎么取数据略
List<SubEdition> SubEditons = new List<SubEdition>() {
new SubEdition(){SEID="101",SubID="1",EdiID="1"}
};//怎么取数据略
List<Chapter> Chapters = new List<Chapter>() {
new Chapter(){ChapterID="10101",SEID="101",ChapterName="第七册"},
new Chapter(){ChapterID="10102",SEID="101",ChapterName="第八册"},
new Chapter(){ChapterID="10901",SEID="109",ChapterName="第N册"}//一条无关的数据
};//怎么取数据略
List<Section> Sections = new List<Section>() {
new Section(){SectionID="1010101",ChapterID="10101",SectionName="第一单元:诗歌"},
new Section(){SectionID="1010102",ChapterID="10101",SectionName="第二单元:爱国主义教育"},
};//怎么取数据略
XElement root = new XElement("Data", Subjects.Select(
iSubject => new XElement("Subject", new object[]
{
new XAttribute("id",iSubject.SubID),
new XAttribute("value", iSubject.SubName),
SubEditons.Where(oSubEdtion => oSubEdtion.SubID == iSubject.SubID).Select(
iSubEditon => new XElement("SubEdion",new object[]
{
new XAttribute("id",iSubEditon.SEID),
new XAttribute("value",Editions.Find(
oEdition=>oEdition.EdiID==iSubEditon.EdiID).EdiName),
Chapters.Where(oChapter=>oChapter.SEID==iSubEditon.SEID).Select(
iChapter=>new XElement("Chapter",new object[]
{
new XAttribute("id",iChapter.ChapterID),
new XAttribute("value",iChapter.ChapterName),
Sections.Where(oSection=>oSection.ChapterID==iChapter.ChapterID).Select(
iSection=>new XElement("Section",new object[]
{
new XAttribute("id",iSection.SectionID),
new XAttribute("value",iSection.SectionName)
}))
}))
}))
}))
);
root.Save("C:\\Data.xml");
}
public class Subject
{
public string SubID { set; get; }
public string SubName { set; get; }
}
public class Edition
{
public string EdiID { set; get; }
public string EdiName { set; get; }
}
public class SubEdition
{
public string SEID { set; get; }
public string SubID { set; get; }
public string EdiID { set; get; }
}
public class Chapter
{
public string ChapterID { set; get; }
public string SEID { set; get; }
public string ChapterName { set; get; }
}
public class Section
{
public string SectionID { set; get; }
public string ChapterID { set; get; }
public string SectionName { set; get; }
}