Visual Basic XML Transform - TechEd demo prep

Published 06 June 07 09:13 AM

Hello from Orlando! I’ve been at TechEd 2007 this week in very sunny Orlando. As part of my demo prep, I had to create a little xml transform to convert the TechEd schedule that I got off the www.msteched.com website in an Excel XML format into a more readable xml file format. I could have done this all with one transform, but the newer XML file format made for good demo fodder to show off the XML Intellisense features coming in Orcas Beta2.

I thought the code was interesting and fun – a great blend of XML properties, XML Literals, and query – so I’ve posted it below:

Imports System.IO

Imports <xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">

 

Module Module1

 

 'Metadata info

 Enum Column

  Code

  Title

  Description

  Track

  Session

  Level

  Speaker

  Room

  Timeslot

 End Enum

 

 Sub Main()

 

  Dim fromFile = "C:\TechEdScheduleExcelFormat.xml"

  Dim toFile = "C:\MyXMLFormat.xml"

  Dim excelXML = XElement.Load(fromFile)

 

  ' Remove first row - metadata info

  excelXML...<ss:Row>.First.Remove()

 

  Dim xml = _

   <?xml version="1.0"?>

   <EventSchedule Event="TechEd2007">

    <%= _

     From session In excelXML...<ss:Row> _

     Let info = session...<ss:Data> _

     Select _

      <Event ID=<%= info(Column.Code).Value %>>

       <Title><%= info(Column.Title).Value %></Title>

       <Description><%= info(Column.Description).Value %></Description>

       <Track><%= info(Column.Track).Value %></Track>

       <Session><%= info(Column.Session).Value %></Session>

       <Level><%= info(Column.Level).Value %></Level>

       <Speaker><%= info(Column.Speaker).Value %></Speaker>

       <Room><%= info(Column.Room).Value %></Room>

       <TimeSlot><%= info(Column.Timeslot).Value %></TimeSlot>

      </Event> _

    %>

   </EventSchedule>

 

   xml.Save(toFile)

   Shell("C:\Program Files\Internet Explorer\iexplore.exe " & toFile, AppWinStyle.MaximizedFocus)

 

 End Sub

End Module

 

All this, so that in the demo, I could:

1)      Open the resulting file, “MyXMLFormat.xml”, in Visual Studio

2)      Right click on the XML menu item

3)      Select create schema to infer an XSD from that file:

Create Schema

 

4)      Save the schema as an XSD and add it as an existing item in my project:

Save as XSD 

5)      And get an awesome Intellisense experience over the XML:

XML Intellisense

 

Pretty cool, no?

by VBTeam
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Bill_McC said on June 6, 2007 12:59 PM:

If you have multiple schemas how does it know which one to use ?

# Beth Massi - Sharing the goodness that is VB said on June 6, 2007 6:29 PM:

Charlie's got a great post of his first day's experience in the TechEd expo. Looks like Amanda is still

# rogerj said on June 7, 2007 12:03 PM:

Amanda,

Process.Start("FileName.xml") from System.Diagnostics is a more .NET Fx-flavored alternative to Shell.

--rj

# VBTeam said on June 14, 2007 1:03 AM:

Hi Bill - Good question. If you have two XSDs in the project, they will both show up at the top level. But because the Intellisense will be filtered based on what you type, the XSDs will quickly disambiguate themselves in the completion lists.

Roger -

The Shell function ships with the .NET frameworks in the Microsoft.VisualBasic.dll - so, it's a fine, Fx flavored, alternative to Process.Start.

-amanda

# The Visual Basic Team said on July 26, 2007 5:30 PM:

Hooray! Visual Basic 2008 Beta2 has been released to the wild today to return to its natural habitat

# The Visual Basic Team said on November 19, 2007 12:27 PM:

Hooray! Today we’ve finally shipped Visual Studio 2008, previously known as “Orcas”, previously known

# The Visual Basic Team said on November 21, 2007 1:24 AM:

Yesterday I promised to post about the hidden gems in Visual Basic and Visual Studio 2008 that you haven&#8217;t

Leave a Comment

(required) 
(optional)
(required) 

This Blog

Syndication

Page view tracker