Джеффри Мак-Манус - Обработка баз данных на Visual Basic®.NET
</tblEmployee>
<tblEmployee>
<ID>4</ID>
<FirstName>Julie</FirstName>
<LastName>Ryan</LastName>
<DepartmentID>1</DepartmentID>
<Salary>4000</Salary>
</tblEmployee>
<tblEmployee>
<ID>5</ID>
<FirstName>Richard</FirstName>
<LastName>Halpin</LastName>
<DepartmentID>2</DepartmentID>
<Salary>10000</Salary>
</tblEmployee>
<tblEmployee>
<ID>6</ID>
<FirstName>Kathleen</FirstName>
<LastName>Johnson</LastName>
<DepartmentID>3</DepartmentID>
<Salary>18000</Salary>
</tblEmployee>
<tblEmployee>
<ID>7</ID>
<FirstName>Sorel</FirstName>
<LastName>Polito</LastName>
<DepartmentID>4</DepartmentID>
<Salary>28000</Salary>
</tblEmployee>
<tblEmployee>
<ID>8</ID>
<FirstName>Sorel</FirstName>
<LastName>Terman</LastName>
<DepartmentID>1</DepartmentID>
<Salary>8000</Salary>
</tblEmployee>
<tblEmployee>
<ID>9</ID>
<FirstName>Randy</FirstName>
<LastName>Hobaica</LastName>
<DepartmentID>2</DepartmentID>
<Salary>18000</Salary>
</tblEmployee>
<tblEmployee>
<ID>10</ID>
<FirstName>Matthew</FirstName>
<LastName>Haglund</LastName>
<DepartmentID>3</DepartmentID>
<Salary>30000</Salary>
</tblEmployee>
<tblEmployee>
<ID>11</ID>
<FirstName>Cathy</FirstName>
<LastName>Vermeren</LastName>
<DepartmentID>4</DepartmentID>
<Salary>0</Salary>
</tblEmployee>
<tblEmployee>
<ID>12</ID>
<FirstName>Brad</FirstName>
<LastName>Townsend</LastName>
<DepartmentID>2</DepartmentID>
<Salary>12000</Salary>
</tblEmployee>
<tblEmployee>
<ID>13</ID>
<FirstName>Jennifer</FirstName>
<LastName>Eves</LastName>
<DepartmentID>2</DepartmentID>
<Salary>26000</Salary>
</tblEmployee>
<tblEmployee>
<ID>14</ID>
<FirstName>Steve</FirstName>
<LastName>Marshall</LastName>
<DepartmentID>3</DepartmentID>
<Salary>42000</Salary>
</tblEmployee>
<tblEmployee>
<ID>15</ID>
<FirstName>Laura</FirstName>
<LastName>Davidson</LastName>
<DepartmentID>4</DepartmentID>
<Salary>60000</Salary>
</tblEmployee>
<tblEmployee>
<ID>16</ID>
<FirstName>Angela</FirstName>
<LastName>Stefanac</LastName>
<DepartmentID>2</DepartmentID>
<Salary>16000</Salary>
</tblEmployee>
<tblEmployee>
<ID>17</ID>
<FirstName>Marjorie</FirstName>
<LastName>Bassett</LastName>
<DepartmentID>2</DepartmentID>
<Salary>34000</Salary>
</tblEmployee>
<tblEmployee>
<ID>18</ID>
<FirstName>Joe</FirstName>
<LastName>Chideya</LastName>
<DepartmentID>3</DepartmentID>
<Salary>54000</Salary>
</tblEmployee>
<tblEmployee>
<ID>19</ID>
<FirstName>Katie</FirstName>
<LastName>Chideya</LastName>
<DepartmentID>4</DepartmentID>
<Salary>76000</Salary>
</tblEmployee>
<tblEmployee>
<ID>20</ID>
<FirstName>Terri</FirstName>
<LastName>Allen</LastName>
<DepartmentID>1</DepartmentID>
<Salary>20000</Salary>
</tblEmployee>
<tblEmployee>
<ID>21</ID>
<FirstName>Mike</FirstName>
<LastName>Doberstein</LastName>
<DepartmentID>2</DepartmentID>
<Salary>42000</Salary>
</tblEmployee>
<tblEmployee>
<ID>22</ID>
<FirstName>Terri</FirstName>
<LastName>Woodruff</LastName>
<DepartmentID>3</DepartmentID>
<Salary>66000</Salary>
</tblEmployee>
<tblEmployee>
<ID>23</ID>
<FirstName>Cathy</FirstName>
<LastName>Rosenthal</LastName>
<DepartmentID>4</DepartmentID>
<Salary>0</Salary>
</tblEmployee>
<tblEmployee>
<ID>24</ID>
<FirstName>Margaret</FirstName>
<LastName>Eves</LastName>
<DepartmentID>1</DepartmentID>
<Salary>24000</Salary>
</tblEmployee>
<tblEmployee>
<ID>25</ID>
<FirstName>Mikki</FirstName>
<LastName>Lemay</LastName>
<DepartmentID>2</DepartmentID>
<Salary>50000</Salary>
</tblEmployee>
<tblEmployee>
<ID>26</ID>
<FirstName>Randy</FirstName>
<LastName>Nelson</LastName>
<DepartmentID>3</DepartmentID>
<Salary>78000</Salary>
</tblEmployee>
<tblEmployee>
<ID>27</ID>
<FirstName>Kathleen</FirstName>
<LastName>Husbands</LastName>
<DepartmentID>4</DepartmentID>
<Salary>108000</Salary>
</tblEmployee>
<tblEmployee>
<ID>28</ID>
<FirstName>Kathleen</FirstName>
<LastName>Eberman</LastName>
<DepartmentID>1</DepartmentID>
<Salary>28000</Salary>
</tblEmployee>
<tblEmployee>
<ID>29</ID>
<FirstName>Richard</FirstName>
<LastName>Rosenthal</LastName>
<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>