Creating XML Schema from XML Data using Visual Studio 2005
by David Hayden ( .NET Developer )
When developing in Visual Studio, sometimes I forget where the features in Visual Studio end and where the features in my add-ins, like ReSharper, CodeRush, etc, begin. Sometimes I will think Visual Studio can do something and it turns out it can't - that feature is there because of an add-in.
The opposite happened to me today. Today I was working with the new XML Data Type in SQL Server 2005 when I needed to create a schema from some XML Data. Now normally this is a 2-second operation with the help of my 3rd party XML tool, but this isn't installed on my new laptop yet and there was no way I was going to leave my perch on the lanai to install it :)
After a little searching, I realized that Visual Studio has the ability to create XML Schema from XML Data and I am probably the last developer to realize this.
If you create an XML file in Visual Studio 2005 and populate it with some sample data as such:
<Chapters>
<Chapter>
<Title>Chapter 1</Title>
<Page>1</Page>
</Chapter>
<Chapter>
<Title>Chapter 2</Title>
<Page>40</Page>
</Chapter>
</Chapters>
There is the handy, dandy XML Menu with an option to create a schema from it:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Chapters">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Chapter">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string" />
<xs:element name="Page" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
It appears this could be done in VS 2003 as well, which means I really need to take a break from some of my tools so I can learn all the capabilities of Visual Studio.
Source: David Hayden ( .NET Developer )