Xml文件创建

时间:2017-04-20 19:32:10

标签: c# xml

我需要帮助我的元素,因为我想确保我的文件与下面的元素和属性匹配

<employees><employee><employeeId>employeeid</employeeId>
<hireDate>Hiredate</hireDate>
</employee>
<employee>
<employeeId>employeeid</employeeId>
<hireDate>Hiredate</hireDate>
</employee>
<employees>

<staffingHours processType="merge">

<staffHours>
<employeeId>employeeid</employeeId>
<workDays>
<workDay>
<date>date</date>
<hourEntries>
<hourEntry>
<hours>hours</hours>
<jobTitleCode>titlecode</jobTitleCode>
<payTypeCode>paycode</payTypeCode>
</hourEntry></hourEntries>
</workDay>
</workDays>
</staffHours>
</staffingHours>

请记住,我从网页上的excel表中获取此数据,下面是生成xml文件的代码,我使用的是gridview记录中的每个循环

 XmlElement Empoyees = xmldoc.CreateElement("Employees");

    XmlElement newDept = xmldoc.CreateElement("Employee");
    XmlElement NurseId = xmldoc.CreateElement("employeeid");
    newDept.AppendChild(NurseId);
    NurseId.InnerText = row.Cells[0].Text;

    XmlElement Firstname = xmldoc.CreateElement("Firstname");
    newDept.AppendChild(Firstname);
    Firstname.InnerText = row.Cells[1].Text;
    //Second node and data source
    XmlElement Lastname = xmldoc.CreateElement("Lastname");
    newDept.AppendChild(Lastname);
    Lastname.InnerText = row.Cells[2].Text;

    //Third node and data source
    XmlElement Starthour = xmldoc.CreateElement("StartDate");
    newDept.AppendChild(Starthour);
    Starthour.InnerText = row.Cells[5].Text;
    //Fourth node and data source
    XmlElement EndDate = xmldoc.CreateElement("EndDate");
    newDept.AppendChild(EndDate);
    EndDate.InnerText = row.Cells[6].Text;

    XmlElement TotalHours = xmldoc.CreateElement("TotalHours");
    newDept.AppendChild(TotalHours);
    TotalHours.InnerText = row.Cells[10].Text;

    XmlElement Starttime = xmldoc.CreateElement("Starttime");
    newDept.AppendChild(Starttime);
    Starttime.InnerText = row.Cells[11].Text;

    XmlElement EndTime = xmldoc.CreateElement("EndTime");
    newDept.AppendChild(EndTime);
    EndTime.InnerText = row.Cells[12].Text;

    //Fourth node and data source
    XmlElement HireDate = xmldoc.CreateElement("HireDate");
    newDept.AppendChild(HireDate);
    HireDate.InnerText = row.Cells[8].Text;
    //write to the xml document
    xmldoc.DocumentElement.InsertAfter(newDept, xmldoc.DocumentElement.LastChild);

感谢任何帮助。

0 个答案:

没有答案