13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Unknown attribute detectedif (e.Attr.Name == "birthdate"){Employee emp = (Employee) e.ObjectBe<strong>in</strong>gDeserialized;DateTime dt = DateTime.Parse(e.Attr.Value);emp.Age = (<strong>in</strong>t) (DateTime.Now.Year - dt.Year);}Populat<strong>in</strong>g Collection PropertiesAn even more complex scenario arises when the source <strong>XML</strong> conta<strong>in</strong>s embedded data,the result of INNER JOIN operations be<strong>in</strong>g rendered <strong>in</strong> <strong>XML</strong>. Consider the follow<strong>in</strong>gstatement:SELECT firstname, lastname, title, hiredate, birthdate,terr.territorydescriptionFROM Employees As employeesINNER JOIN EmployeeTerritories AS empterrON employees.employeeid=empterr.employeeidINNER JOIN Territories AS terrON empterr.territoryid=terr.territoryidWHERE employees.employeeid=@empIDFOR <strong>XML</strong> AUTOThe <strong>XML</strong> output <strong>for</strong> the empID parameter that equals 1 is shown here:This output changes a little bit if you use the ELEMENTS clause, as follows:NancyDavolio...WiltonNewardThe application is always notified of any elements through an UnknownElementevent. Suppose you also want any territory description to populate a Str<strong>in</strong>gCollectionproperty <strong>in</strong> the Employee class. The follow<strong>in</strong>g code shows how to handle the event andaccumulate the data <strong>for</strong> an unknown element <strong>in</strong> the str<strong>in</strong>g collection:if (e.Element.Name == "terr")415

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!