Presentation is loading. Please wait.

Presentation is loading. Please wait.

Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced.

Similar presentations


Presentation on theme: "Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced."— Presentation transcript:

1 Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced

2 Visual Basic 9 Goals Simplify querying data –Integrate query and transform operations –Unify query of object, relational, and XML data Simplify working with XML –Impose structure on XML w/no schema –Produce XML documents quickly –Access XML members easily

3 Conquering XML (Agenda) Visual Basic 9 & the XML Data Type –XML Literals –XML Properties Explanation of the LINQ to XML API –Mapping the XML Data Type to the LINQ to XML API Using the XML data type in queries Writing an XML transform in VB Miscellaneous tips and tricks …Be the most productive when programming against XML

4 Language INtegrated Query (LINQ) LINQ enabled data sources LINQ To Objects Objects LINQ To XML XML LINQ enabled ADO.NET LINQ To Datasets LINQ To SQL LINQ To Entities Relational Others… VB C#.NET Language-Integrated Query

5 DEMO

6 Programming XML Today Dim doc As New XmlDocument() Dim contacts As XMLElement = doc.CreateElement("contacts") For Each cust in Customers If (cust.Country = "USA") Dim e As XMLElement = doc.CreateElement("contact") Dim name As XMLElement = doc.CreateElement("name") name.InnerText = c.CompanyName e.AppendChild(name) Dim phone As XMLElement = doc.CreateElement("phone") phone.InnerText = cust.Phone e.AppendChild(phone) contacts.AppendChild(e) End If Next doc.AppendChild(contacts) <contacts> Great Lakes Food Great Lakes Food (503) 555-7123 (503) 555-7123 …</contacts> Imperative model Document- centric No integrated queries Memory- intensive

7 LINQ to XML Dim contacts As New XElement("contacts", _ From cust in customers _ Where cust.Country = "USA“ _ Select New XElement("contact", _ New XElement("name", cust.CompanyName), _ New XElement("phone", cust.Phone) _ ) Declarative model Element- centric Integrated queries Smaller and faster

8 LINQ to XML Language integrated query for XML –Expressive power of XPath/Xquery –But with Visual Basic as your programming language! –No conceptual barrier between XML and code Leverages experience with DOM –Element-centric, not document-centric –Symmetry in element/attribute APIs –Functional construction –Text nodes are just strings –Simplified XML namespace support –Faster and smaller than DOM

9 DEMO

10 Integrated XML in Visual Basic Dim contacts = _ <%= _ From cust In customers _ Where cust.Country = "USA" _ Select _ %> Infers Xml.Linq XElementInfers Xml.Linq XElement No conceptual barrier WYSIWYG! Expression holes for computed values

11 XML Literals Shorthand for object creation Dim emp = _ Joe 28 Engineering Dim emp = _ New XElement("employee", _ New XElement("name", "Joe"), _ New XElement("age", 28), _ New XElement("department", _ New XElement("name", "Engineering"), _ New XAttribute("id", 432)))

12 DEMO

13 Element access covers all XML axes Dim employees As XElement = GetCurrentEmployeesByDept(“IT”) Dim deptID As Integer = employees.Attribute(“DeptID") Dim emp As XElement = employees.Descendents(“Employee")(0) Dim empDOB As Date = emp.Element(“DateOfBirth“).Value XML Element Access Dim employees As XElement = GetCurrentEmployeesByDept(“IT”) Dim deptID As Integer = employees.@DeptID Dim emp As XElement = employees… (0) Dim empDOB As Date = emp..Value Attributes Descendents Elements Nancy Davolio Nancy Davolio Sales Representative Sales Representative 1948-12-08 1948-12-08 Andrew Fuller Andrew Fuller Vice President, Sales Vice President, Sales 1952-02-19 1952-02-19 </Employees>

14 DEMO

15

16 Call to action Download Beta1! http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx Join discussion on MSDN LINQ forum http://forums.microsoft.com/msdn/showforum.aspx?forumid=123 Blogosphere/Community: –VBDevCenter: http://msdn.microsoft.com/vbasichttp://msdn.microsoft.com/vbasic –VB Team: http://blogs.msdn.com/vbteamhttp://blogs.msdn.com/vbteam –Paul Vick: http://www.panopticoncentral.nethttp://www.panopticoncentral.net

17 ©2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.


Download ppt "Live from Redmond: WebCast Conquering XML with Visual Basic 9 Amanda Silver Lead Program Manager Visual Basic Level: Starts Easy, Finishes Advanced."

Similar presentations


Ads by Google