Выбрать главу

  <DepartmentID>2</DepartmentID>

  <Salary>58000</Salary>

 </tblEmployee>

 <tblEmployee>

  <ID>30</ID>

  <FirstName>Mike</FirstName>

  <LastName>Woodruff</LastName>

  <DepartmentID>3</DepartmentID>

  <Salary>90000</Salary>

 </tblEmployee>

</NewDataSet>

К сожалению, данный XML-файл содержит список сотрудников, который не сгруппирован по отделам. Несмотря на созданное отношение между родительской таблицей tblDepartment и дочерней таблицей tblEmployee полученный XML-файл содержит данные отдельно для каждой таблицы. Для вложения дочерних элементов из таблицы tblEmployee в родительские элементы из таблицы tblDepartment нужно указать значение True для свойства Nested объекта-отношения Relation.

dsEmployees.Relations("DepartmentEmployees").Nested = True

После вставки этой строки кода перед строкой сохранения данных

dsInventory.WriteXml("..\Inventory.xml", XmlWriteMode.WriteSchema)

будет получен XML-файл Employees.xml, показанный в листинге 10.11.

 Листинг 10.11. XML-файл Employees.xml с вложением дочерних элементов из таблицы tblEmployee в родительские элементы из таблицы tblDepartment

<?xml version="1.0" standalone="yes"?>

<NewDataSet>

 <tblDepartment>

  <ID>1</ID>

  <DepartmentName>Administration</DepartmentName>

  <tblEmployee>

   <ID>2035</ID>

   <FirstName>Julie</FirstName>

   <LastName>Ryan</LastName>

   <DepartmentID>1</DepartmentID>

   <Salary>4000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2039</ID>

   <FirstName>Sorel</FirstName>

   <LastName>Terman</LastName>

   <DepartmentID>1</DepartmentID>

   <Salary>8000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2051</ID>

   <FirstName>Terri</FirstName>

   <LastName>Allen</LastName>

   <DepartmentID>1</DepartmentID>

   <Salary>20000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2055</ID>

   <FirstName>Margaret</FirstName>

   <LastName>Eves</LastName>

   <DepartmentID>1</DepartmentID>

   <Salary>24000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2059</ID>

   <FirstName>Kathleen</FirstName>

   <LastName>Eberman</LastName>

   <DepartmentID>1</DepartmentID>

   <Salary>28000</Salary>

  </tblEmployee>

 </tblDepartment>

 <tblDepartment>

  <ID>2</ID>

  <DepartmentName>Engineering</DepartmentName>

  <tblEmployee>

   <ID>2032</ID>

   <FirstName>Carole</FirstName>

   <LastName>Vermeren</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>222</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2033</ID>

   <FirstName>Cathy</FirstName>

   <LastName>Johnson</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>13000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2036</ID>

   <FirstName>Richard</FirstName>

   <LastName>Halpin</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>10000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2040</ID>

   <FirstName>Randy</FirstName>

   <LastName>Hobaica</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>18000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2043</ID>

   <FirstName>Brad</FirstName>

   <LastName>Townsend</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>12000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2044</ID>

   <FirstName>Jennifer</FirstName>

   <LastName>Eves</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>26000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>204V</ID>

   <FirstName>Angela</FirstName>

   <LastName>Stefanac</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>16000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2048</ID>

   <FirstName>Marjorie</FirstName>

   <LastName>Bassett</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>34000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2052</ID>

   <FirstName>Mike</FirstName>

   <LastName>Doberstein</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>42000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2056</ID>

   <FirstName>Mikki</FirstName>

   <LastName>Lemay</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>50000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2060</ID>

   <FirstName>Richard</FirstName>

   <LastName>Rosenthal</LastName>

   <DepartmentID>2</DepartmentID>

   <Salary>58000</Salary>

  </tblEmployee>

 </tblDepartment>

 <tblDepartment>

  <ID>3</ID>

  <DepartmentName>Sales</DepartmentName>

  <tblEmployee>

   <ID>2037</ID>

   <FirstName>Kathleen</FirstName>

   <LastName>Johnson</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>18000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2041</ID>

   <FirstName>Matthew</FirstName>

   <LastName>Haglund</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>30000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2045</ID>

   <FirstName>Steve</FirstName>

   <LastName>Marshall</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>42000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2049</ID>

   <FirstName>Joe</FirstName>

   <LastName>Chideya</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>54000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2053</ID>

   <FirstName>Terri</FirstName>

   <LastName>Woodruff</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>66000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2057</ID>

   <FirstName>Randy</FirstName>

   <LastName>Nelson</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>78000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2061</ID>

   <FirstName>Mike</FirstName>

   <LastName>Woodruff</LastName>

   <DepartmentID>3</DepartmentID>

   <Salary>90000</Salary>

  </tblEmployee>

 </tblDepartment>

 <tblDepartment>

  <ID>4</ID>

  <DepartmentName>Marketing</DepartmentName>

  <tblEmployee>

   <ID>2034</ID>

   <FirstName>Eric</FirstName>

   <LastName >Haglund</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>12000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2038</ID>

   <FirstName>Sorel</FirstName>

   <LastName>Polito</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>28000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2042</ID>

   <FirstName>Cathy</FirstName>

   <LastName>Vermeren</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>0</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2046</ID>

   <FirstName>Laura</FirstName>

   <LastName>Davidson</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>60000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2050</ID>

   <FirstName>Katie</FirstName>

   <LastName>Chideya</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>76000</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2054</ID>

   <FirstName>Cathy</FirstName>

   <LastName>Rosenthal</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>5555</Salary>

  </tblEmployee>

  <tblEmployee>

   <ID>2058</ID>

   <FirstName>Kathleen</FirstName>

   <LastName>Husbands</LastName>

   <DepartmentID>4</DepartmentID>

   <Salary>108000</Salary>

  </tblEmployee>

 </tblDepartment>

</NewDataSet>