beth massi program manager visual studio community

18
Conquering XML with Visual Basic 9 Beth Massi Program Manager Visual Studio Community

Upload: lynne-ross

Post on 23-Dec-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

Conquering XML with Visual Basic 9

Beth MassiProgram ManagerVisual Studio Community

Who Am I?PM on the VS Community team @ Microsoft

VB Community Champion! Working directly with the VB team Provide content production and management for the VB Dev Center http://msdn.com/vbasic

Ex-Microsoft Architect MVP Ex-.NET Systems Architect / Lead Programmer at various healthcare companies and consulting firmsOver 13 years of information systems experience

http://blogs.msdn.com/bethmassi

Visual Basic 9 Goals

Simplify querying dataIntegrate query and transform operationsUnify query of object, relational, and XML data

Simplify working with XMLImpose structure on XML w/no schemaProduce XML documents quicklyAccess XML members easily

Conquering XML (Agenda)

Visual Basic 9 & the XML Data TypeXML LiteralsXML Properties

LINQ to XML APIMapping the XML Data Type to the LINQ to XML API

Creating, Querying, Transforming XML in VBEvolution Away from the DOMXML Properties and Enabling IntelliSenseMiscellaneous tips and tricks

…Be the most productive when programming against XML

Language INtegrated Query (LINQ)

LINQ enabled data sources

LINQTo Objects

Objects

LINQTo XML

<book> <title/> <author/> <price/></book>XM

L

LINQ enabled ADO.NET

LINQTo Datasets

LINQTo SQL

LINQTo Entities

Relational

Others…VB C#

.NET Language-Integrated Query

Linq to XML and the XML Data Type(Getting Started)

demo

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 IfNextdoc.AppendChild(contacts)

<contacts> <contact> <name>Great Lakes Food</name> <phone>(503) 555-7123</phone> </contact> …</contacts>

Imperative model

Document-centric

No integrated queries

Memory-intensive

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

LINQ to XMLLanguage integrated query for XML

Expressive power of XPath/XqueryBut with Visual Basic as your programming languageNo conceptual barrier between XML and code

Leverages experience with DOMElement-centric, not document-centricSymmetry in element/attribute APIsFunctional constructionText nodes are just stringsSimplified XML namespace supportFaster and smaller than DOM

LINQ to XML(aka System.XML.Linq)Creating, Querying, Transforming XML

demo

Integrated XML in Visual Basic

Dim contacts = _ <contacts> <%= _ From cust In customers _ Where cust.Country = "USA" _ Select <contact> <name><%= cust.CompanyName %></name> <phone><%= cust.Phone %></phone> </contact> _ %> </contacts>

Infers Xml.Linq XElement

No conceptual barrier

WYSIWYG!

Expression holes for computed

values

XML Literals

Shorthand for object creationDim emp = _ <employee> <name>Joe</name> <age>28</age> <department id="432"> <deptname>Engineering</deptname> </department> </employee>

Dim emp = _ New XElement("employee", _ New XElement("name", "Joe"), _ New XElement("age", 28), _ New XElement("department", _ New XElement("name", "Engineering"), _ New XAttribute("id", 432)))

Deep Dive into XML Literals(Evolution Away from the DOM)

demo

XML Element AccessElement 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“).ValueDim employees As XElement = GetCurrentEmployeesByDept(“IT”)Dim deptID As Integer = employees.@DeptIDDim emp As XElement = employees…<Employee>(0)Dim empDOB As Date = emp.<DateOfBirth>.Value

Attributes

DescendentsElements

<Employees Dept="IT"> <Employee> <Name>Nancy Davolio</Name> <Title>Sales Representative</Title> <DateOfBirth>1948-12-08</DateOfBirth> </Employee> <Employee> <Name>Andrew Fuller</Name> <Title>Vice President, Sales</Title> <DateOfBirth>1952-02-19</DateOfBirth> </Employee></Employees>

XML Properties and Enabling IntelliSense

demo

Tips and Tricks

demo

Call to actionDownload Beta 2!http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspxRTM = End of Nov! (very soon)

LINQ How-To Videos http://msdn2.microsoft.com/en-us/vbasic/bb466226.aspx#linq

Blogosphere/Community:VB Dev Center: http://msdn.com/vbasicVB Team: http://blogs.msdn.com/vbteam Beth Massi: http://blogs.msdn.com/bethmassiPaul Vick: http://www.panopticoncentral.net

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