A group blog from members of the VB team
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:
4) Save the schema as an XSD and add it as an existing item in my project:
5) And get an awesome Intellisense experience over the XML:
Pretty cool, no?
If you have multiple schemas how does it know which one to use ?
Charlie's got a great post of his first day's experience in the TechEd expo. Looks like Amanda is still
Amanda,
Process.Start("FileName.xml") from System.Diagnostics is a more .NET Fx-flavored alternative to Shell.
--rj
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
Hooray! Visual Basic 2008 Beta2 has been released to the wild today to return to its natural habitat
Hooray! Today we’ve finally shipped Visual Studio 2008, previously known as “Orcas”, previously known
Yesterday I promised to post about the hidden gems in Visual Basic and Visual Studio 2008 that you haven’t