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

Beth Massi Program Manager Visual Studio Community.

Dec 23, 2015

Download

Documents

Lynne Ross
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Beth Massi Program Manager Visual Studio Community.

Conquering XML with Visual Basic 9

Beth MassiProgram ManagerVisual Studio Community

Page 2: Beth Massi Program Manager Visual 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

Page 3: Beth Massi Program Manager Visual Studio Community.

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

Page 4: Beth Massi Program Manager Visual Studio Community.

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

Page 5: Beth Massi Program Manager Visual Studio Community.

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

Page 6: Beth Massi Program Manager Visual Studio Community.

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

demo

Page 7: Beth Massi Program Manager Visual Studio Community.

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

Page 8: Beth Massi Program Manager Visual Studio Community.

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

Page 9: Beth Massi Program Manager Visual Studio Community.

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

Page 10: Beth Massi Program Manager Visual Studio Community.

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

demo

Page 11: Beth Massi Program Manager Visual Studio Community.

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

Page 12: Beth Massi Program Manager Visual Studio Community.

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)))

Page 13: Beth Massi Program Manager Visual Studio Community.

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

demo

Page 14: Beth Massi Program Manager Visual Studio Community.

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>

Page 15: Beth Massi Program Manager Visual Studio Community.

XML Properties and Enabling IntelliSense

demo

Page 16: Beth Massi Program Manager Visual Studio Community.

Tips and Tricks

demo

Page 17: Beth Massi Program Manager Visual Studio Community.

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

Page 18: Beth Massi Program Manager Visual Studio Community.

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