嗨,我有一个包含字段名称和类型的 Excel,如下例所示。
ID : INT
First_Name : String
Last_Name : String
Phone number : String
我想根据我的描述生成一个 XSD。
有这个工具吗?
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>
在记事本中,像这样编写新架构:
<?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>
将文件另存为 schema.xml
结果将如下所示: