Reputation: 467
Hi, I have an Excel that contains fields names and type like the following example.
ID : INT
First_Name : String
Last_Name : String
Phone number : String
I would like to generate an XSD from the description that I have.
Is there a tool for this?
Upvotes: 4
Views: 22401
Reputation: 31750
Note: there is no solution using just Excel.
This was true in 2013 when the OP asked the question, and is still true now, as far as I can tell.
The answers provided on this page, though they use external tooling, represent the only solutions on the internet at this time, and have since been viewed 13,000 times.
If you or anyone you know have a solution using only Excel to generate XSD, please add it, because this is clearly something that would help many people.
Model the class in code:
public class Something
{
public int ID { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string Phone_number { get; set; }
}
Save it to a .cs file and then compile it.
and then use xsd.exe to generate the xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Something" nillable="true" type="Something" />
<xs:complexType name="Something">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="ID" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="First_Name" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Last_Name" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Phone_number" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Upvotes: 3
Reputation: 31364
In notepad, write your new schema like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<ID>12345</ID>
<FirstName>First Name</FirstName>
<LastName>Last Name</LastName>
<PhoneNumber>555-555-5555</PhoneNumber>
</record>
<record>
<ID>12346</ID>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<PhoneNumber>555-555-5555</PhoneNumber>
</record>
</data-set>
Save the file as schema.xml
Result will look like this:
Upvotes: 2