bitbonk

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

Hi,

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="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:element name="Document">

<xs:complexType>

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

<xs:element name="Table1">

<xs:complexType>

<xs:sequence>

<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:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

<xs:unique name="DocumentKey1">

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

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

</xs:unique>

</xs:element>

</xs:schema>

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.