Is there a way (preferably using the xml schema designer of Visual Studio) to genrate an xml schema from an existing database where the columns of the tables become attribute definitions in the xsd When I drag a db table onto the design surface the columns unfortunately become element definitions.

Re: XML and the .NET Framework generating a xsd from a db where columns become attributes

Sinan Ussakli - MSFT


As far as I know there is not.

Once you drag and drop you will have the following:

Code Block

< xml version="1.0" encoding="utf-8" >

<xs:schema targetNamespace="" elementFormDefault="qualified" xmlns="" xmlns:mstns="" xmlns:xs="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:element name="Document">


<xs:choice minOccurs="0" maxOccurs="unbounded">

<xs:element name="Table1">



<xs:element name="ID" type="xs:int" />

<xs:element name="Field1" type="xs:string" minOccurs="0" />

<xs:element name="Field2" type="xs:string" minOccurs="0" />

<xs:element name="Field3" type="xs:string" minOccurs="0" />

<xs:element name="Field4" type="xs:string" minOccurs="0" />






<xs:unique name="DocumentKey1">

<xs:selector xpath=".//mstns:Table1" />

<xs:field xpath="mstns:ID" />




1. You need to remove <xsTongue Tiedequence> and </xsTongue Tiedequence> under Table1 element's complexType element.

2. rename xs:element to xs:attribute

3. remove minOccurs="0" in all xs:attributes.

This will be valid. you may do massive regex find and replace texts to do this at development time.